Branch data Line data Source code
1 : : /* zxcot.c - CoT (Circle-of-Trust) management tool: list CoT, add metadata to CoT
2 : : * Copyright (c) 2009-2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
3 : : * This is confidential unpublished proprietary source code of the author.
4 : : * NO WARRANTY, not even implied warranties. Contains trade secrets.
5 : : * Distribution prohibited unless authorized in writing.
6 : : * Licensed under Apache License 2.0, see file COPYING.
7 : : * $Id: zxcot.c,v 1.5 2009-11-29 12:23:06 sampo Exp $
8 : : *
9 : : * 27.8.2009, created --Sampo
10 : : */
11 : :
12 : : #include "platform.h" /* for dirent.h */
13 : :
14 : : #include <string.h>
15 : : #include <stdio.h>
16 : : #include <fcntl.h>
17 : : #include <errno.h>
18 : :
19 : : #include "errmac.h"
20 : : #include "zx.h"
21 : : #include "zxid.h"
22 : : #include "zxidutil.h"
23 : : #include "zxidconf.h"
24 : : #include "c/zxidvers.h"
25 : : #include "c/zx-const.h"
26 : : #include "c/zx-ns.h"
27 : : #include "c/zx-data.h"
28 : :
29 : : char* help =
30 : : "zxcot - Circle-of-Trust and metadata management tool R" ZXID_REL "\n\
31 : : Copyright (c) 2009-2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.\n\
32 : : NO WARRANTY, not even implied warranties. Licensed under Apache License v2.0\n\
33 : : See http://www.apache.org/licenses/LICENSE-2.0\n\
34 : : Send well researched bug reports to the author. Home: zxid.org\n\
35 : : \n\
36 : : Usage: zxcot [options] [dir] # Gives listing of metadata\n\
37 : : zxcot -a [options] [dir] <meta.xml\n\
38 : : zxcot -b [options] [dir] <epr.xml\n\
39 : : curl https://site.com/metadata.xml | zxcot -a [options] [dir]\n\
40 : : zxcot -g https://site.com/metadata.xml [options] [dir]\n\
41 : : zxcot -m [options] >meta.xml # Generate our own metadata\n\
42 : : zxcot -p https://site.com/metadata.xml\n\
43 : : [dir] CoT directory. Default /var/zxid/cot\n\
44 : : -c CONF Optional configuration string (default -c PATH=/var/zxid/)\n\
45 : : Most of the configuration is read from /var/zxid/zxid.conf\n\
46 : : -a Add metadata from stdin\n\
47 : : -b Register Web Service, add Service EPR from stdin\n\
48 : : -bs Register Web Service and Bootstrap, add Service EPR from stdin\n\
49 : : -e endpoint abstract entid servicetype Dump EPR to stdout.\n\
50 : : -g URL Do HTTP(S) GET to URL and add as metadata (if compiled w/libcurl)\n\
51 : : -n Dryrun. Do not actually add the metadata. Instead print it to stdout.\n\
52 : : -s Swap columns, for easier sorting by URL\n\
53 : : -m Output metadata of this installation (our own metadata)\n\
54 : : -p ENTID Print sha1 name corresponding to an entity ID.\n\
55 : : -v Verbose messages.\n\
56 : : -q Be extra quiet.\n\
57 : : -d Turn on debugging.\n\
58 : : -h This help message\n\
59 : : -- End of options\n\
60 : : \n\
61 : : zxcot -e http://idp.tas3.pt:8081/zxididp?o=S 'TAS3 Default Discovery Service (ID-WSF 2.0)' http://idp.tas3.pt:8081/zxididp?o=B urn:liberty:disco:2006-08 | zxcot -b\n\
62 : : \n";
63 : :
64 : : #define ZXID_MAX_MD (256*1024)
65 : :
66 : : int swap = 0;
67 : : int addmd = 0;
68 : : int regsvc = 0;
69 : : int regbs = 0;
70 : : int genmd = 0;
71 : : int dryrun = 0;
72 : : int inflate_flag = 2; /* Auto */
73 : : int verbose = 1;
74 : : char buf[ZXID_MAX_MD+1];
75 : : char* mdurl = 0;
76 : : char* entid = 0;
77 : : char* cotdir = ZXID_PATH ZXID_COT_DIR;
78 : : char* dimddir = ZXID_PATH ZXID_DIMD_DIR;
79 : : char* uiddir = ZXID_PATH ZXID_UID_DIR;
80 : : zxid_conf* cf = 0;
81 : :
82 : : /* Called by: main x8, zxcall_main, zxcot_main, zxdecode_main */
83 : : static void opt(int* argc, char*** argv, char*** env)
84 : 20 : {
85 : : int len;
86 : : struct zx_str* ss;
87 : :
88 [ + + ]: 20 : if (*argc <= 1) return;
89 : :
90 : : while (1) {
91 : 46 : ++(*argv); --(*argc);
92 : :
93 [ + + + + ]: 46 : if (!(*argc) || ((*argv)[0][0] != '-')) break; /* normal exit from options loop */
94 : :
95 [ + + + + : 32 : switch ((*argv)[0][1]) {
+ + + + +
+ + + +
+ ]
96 [ + - ]: 1 : case '-': if ((*argv)[0][2]) break;
97 : 1 : ++(*argv); --(*argc);
98 : : DD("End of options by --");
99 : 1 : return; /* -- ends the options */
100 : :
101 : : case 'a':
102 [ + - ]: 2 : switch ((*argv)[0][2]) {
103 : : case '\0':
104 : 2 : ++addmd;
105 : 2 : continue;
106 : : }
107 : 0 : break;
108 : :
109 : : case 'b':
110 [ + + - ]: 3 : switch ((*argv)[0][2]) {
111 : : case 's':
112 : 1 : ++regsvc;
113 : 1 : ++regbs;
114 : 1 : dimddir = ZXID_PATH "idp" ZXID_DIMD_DIR;
115 : 1 : uiddir = ZXID_PATH "idp" ZXID_UID_DIR;
116 : 1 : continue;
117 : : case '\0':
118 : 2 : ++regsvc;
119 : 2 : dimddir = ZXID_PATH "idp" ZXID_DIMD_DIR;
120 : 2 : continue;
121 : : }
122 : 0 : break;
123 : :
124 : : case 'c':
125 [ + - ]: 2 : switch ((*argv)[0][2]) {
126 : : case '\0':
127 : 2 : ++(*argv); --(*argc);
128 [ + - ]: 2 : if ((*argc) < 1) break;
129 : 2 : zxid_parse_conf(cf, (*argv)[0]);
130 : 2 : continue;
131 : : }
132 : 0 : break;
133 : :
134 : : case 'e':
135 [ + - ]: 3 : switch ((*argv)[0][2]) {
136 : : case '\0':
137 [ + - ]: 3 : if ((*argc) < 4) break;
138 : 3 : printf(
139 : : "<a:EndpointReference xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
140 : : "xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" "
141 : : "notOnOrAfter=\"2037-01-05T23:03:59.001Z\" "
142 : : "wsu:Id=\"EPRID92lFPo3ZNEt_3rHtJFoU\">"
143 : : "<a:Address>%s</a:Address>"
144 : : "<a:Metadata>"
145 : : "<sbf:Framework xmlns:sbf=\"urn:liberty:sb\" version=\"2.0\"></sbf:Framework>"
146 : : "<di:Abstract xmlns:di=\"urn:liberty:disco:2006-08\">%s</di:Abstract>"
147 : : "<di:ProviderID xmlns:di=\"urn:liberty:disco:2006-08\">%s</di:ProviderID>"
148 : : "<di:ServiceType xmlns:di=\"urn:liberty:disco:2006-08\">%s</di:ServiceType>"
149 : : "</a:Metadata>"
150 : : "</a:EndpointReference>", (*argv)[1], (*argv)[2], (*argv)[3], (*argv)[4]);
151 : 3 : exit(0);
152 : : }
153 : 0 : break;
154 : :
155 : : case 'g':
156 [ + - ]: 2 : switch ((*argv)[0][2]) {
157 : : case '\0':
158 : 2 : ++(*argv); --(*argc);
159 [ + - ]: 2 : if ((*argc) < 1) break;
160 : 2 : mdurl = (*argv)[0];
161 : 2 : ++addmd;
162 : 2 : continue;
163 : : }
164 : 0 : break;
165 : :
166 : : case 'd':
167 [ + + - ]: 2 : switch ((*argv)[0][2]) {
168 : : case '\0':
169 : 1 : ++zx_debug;
170 : 1 : continue;
171 : : case 'c':
172 : 1 : ss = zxid_show_conf(cf);
173 : 1 : fprintf(stderr, "\n======== CONF ========\n%.*s\n^^^^^^^^ CONF ^^^^^^^^\n",ss->len,ss->s);
174 : 1 : continue;
175 : : }
176 : 0 : break;
177 : :
178 : : case 's':
179 [ + - ]: 4 : switch ((*argv)[0][2]) {
180 : : case '\0':
181 : 4 : ++swap;
182 : 4 : continue;
183 : : }
184 : 0 : break;
185 : :
186 : : case 'p':
187 [ + - ]: 1 : switch ((*argv)[0][2]) {
188 : : case '\0':
189 : 1 : ++(*argv); --(*argc);
190 [ + - ]: 1 : if ((*argc) < 1) break;
191 : 1 : entid = (*argv)[0];
192 : 1 : continue;
193 : : }
194 : 0 : break;
195 : :
196 : : case 'm':
197 [ + - ]: 3 : switch ((*argv)[0][2]) {
198 : : case '\0':
199 : 3 : ++genmd;
200 : 3 : continue;
201 : : }
202 : 0 : break;
203 : :
204 : : case 'n':
205 [ + - ]: 3 : switch ((*argv)[0][2]) {
206 : : case '\0':
207 : 3 : ++dryrun;
208 : 3 : continue;
209 : : }
210 : 0 : break;
211 : :
212 : : #if 0
213 : : case 'l':
214 : : switch ((*argv)[0][2]) {
215 : : case 'i':
216 : : if (!strcmp((*argv)[0],"-license")) {
217 : : extern char* license;
218 : : fprintf(stderr, license);
219 : : exit(0);
220 : : }
221 : : break;
222 : : }
223 : : break;
224 : : #endif
225 : :
226 : : case 'q':
227 [ + - ]: 1 : switch ((*argv)[0][2]) {
228 : : case '\0':
229 : 1 : verbose = 0;
230 : 1 : continue;
231 : : }
232 : 0 : break;
233 : :
234 : : case 'v':
235 [ + - ]: 4 : switch ((*argv)[0][2]) {
236 : : case '\0':
237 : 4 : ++verbose;
238 : 4 : continue;
239 : : }
240 : : break;
241 : :
242 : : }
243 : : /* fall thru means unrecognized flag */
244 [ + - ]: 1 : if (*argc)
245 : 1 : fprintf(stderr, "Unrecognized flag `%s'\n", (*argv)[0]);
246 [ + - ]: 1 : if (verbose>1) {
247 : 1 : printf(help);
248 : 1 : exit(0);
249 : : }
250 : 0 : fprintf(stderr, help);
251 : : /*fprintf(stderr, "version=0x%06x rel(%s)\n", zxid_version(), zxid_version_str());*/
252 : 0 : exit(3);
253 : 27 : }
254 [ + + ]: 14 : if (*argc) {
255 : 2 : uiddir = dimddir = cotdir = (*argv)[0];
256 : 2 : len = strlen(cotdir);
257 [ + - ]: 2 : if (cotdir[len-1] != '/') {
258 : 2 : cotdir = malloc(len+1);
259 : 2 : strcpy(cotdir, (*argv)[0]);
260 : 2 : cotdir[len] = '/';
261 : 2 : cotdir[len+1] = 0;
262 : 2 : uiddir = dimddir = cotdir;
263 : : }
264 : : }
265 : : }
266 : :
267 : : /* --------------- reg_svc --------------- */
268 : :
269 : : /*() IdP and Discovery. Register service metadata to /var/zxid/idpdimd/XX,
270 : : * and possibly boostrap to /var/zxid/idpuid/.all/.bs/YY
271 : : *
272 : : * bs_reg:: Register-also-as-bootstrap flag
273 : : * dry_run:: nonzero: do not write anything
274 : : * ddimd:: Discovery metadata directory, such as /var/zxid/idpdimd/
275 : : * duid:: uid dir such as /var/zxid/idpuid/
276 : : * returns:: 0 on success, nonzero on error. */
277 : :
278 : : /* Called by: zxcot_main */
279 : : static int zxid_reg_svc(zxid_conf* cf, int bs_reg, int dry_run, const char* ddimd, const char* duid)
280 : 2 : {
281 : : char sha1_name[28];
282 : : char path[ZXID_MAX_BUF];
283 : : char* p;
284 : : //char* uiddir;
285 : : int got, fd;
286 : : struct zx_root_s* r;
287 : : zxid_epr* epr;
288 : : struct zx_str* ss;
289 : : struct zx_str* tt;
290 : :
291 : 2 : read_all_fd(0, buf, sizeof(buf)-1, &got); /* Read EPR */
292 : 2 : buf[got] = 0;
293 : 2 : p = buf;
294 : :
295 : 2 : r = zx_dec_zx_root(cf->ctx, got, buf, "cot reg_svc");
296 [ + - - + ]: 2 : if (!r || !r->EndpointReference) {
297 : 0 : ERR("Failed to parse <EndpointReference> buf(%.*s)", got, buf);
298 : 0 : return 1;
299 : : }
300 : 2 : epr = r->EndpointReference;
301 [ + - + - : 2 : if (!ZX_SIMPLE_ELEM_CHK(epr->Address)) {
+ - + - +
- - + ]
302 : 0 : ERR("<EndpointReference> MUST have <Address> element buf(%.*s)", got, buf);
303 : 0 : return 1;
304 : : }
305 [ - + ]: 2 : if (!epr->Metadata) {
306 : 0 : ERR("<EndpointReference> MUST have <Metadata> element buf(%.*s)", got, buf);
307 : 0 : return 1;
308 : : }
309 [ + - + - : 2 : if (!ZX_SIMPLE_ELEM_CHK(epr->Metadata->ProviderID)) {
+ - + - +
- - + ]
310 : 0 : ERR("<EndpointReference> MUST have <Metadata> with <ProviderID> element buf(%.*s)", got, buf);
311 : 0 : return 1;
312 : : }
313 [ - + ]: 2 : if (!epr->Metadata->ServiceType) {
314 : 0 : ERR("<EndpointReference> MUST have <ServiceType> element buf(%.*s)", got, buf);
315 : 0 : return 1;
316 : : }
317 : :
318 : : /* *** possibly add something here and double check the required fields are available. */
319 : :
320 : 2 : ss = zx_easy_enc_elem_opt(cf, &epr->gg);
321 [ - + ]: 2 : if (!ss)
322 : 0 : return 2;
323 : :
324 : : #if 0
325 : : // *** wrong
326 : : tt = ZX_GET_CONTENT(epr->Metadata->ProviderID);
327 : : #else
328 [ + - + - : 2 : tt = ZX_GET_CONTENT(epr->Metadata->ServiceType);
+ - ]
329 : : #endif
330 : 2 : got = MIN(tt->len, sizeof(path)-1);
331 [ + - ]: 2 : memcpy(path, tt?tt->s:"", got);
332 : 2 : path[got] = 0;
333 : 2 : zxid_fold_svc(path, got);
334 : :
335 : 2 : sha1_safe_base64(sha1_name, ss->len, ss->s);
336 : 2 : sha1_name[27] = 0;
337 : :
338 [ + - ]: 2 : if (verbose)
339 : 2 : fprintf(stderr, "Registering metadata in %s%s,%s\n", ddimd, path, sha1_name);
340 : :
341 [ + + ]: 2 : if (dry_run) {
342 [ + - ]: 1 : if (verbose)
343 : 1 : fprintf(stderr, "Register EPR dry run. Would have written to path(%s%s,%s). "
344 : : "You may also want to\n"
345 : : " touch %s.all/.bs/%s,%s\n\n", ddimd, path, sha1_name, uiddir, path, sha1_name);
346 : 1 : fflush(stdin);
347 : 1 : write_all_fd(fdstdout, ss->s, ss->len);
348 : 1 : zx_str_free(cf->ctx, ss);
349 : 1 : return 0;
350 : : }
351 : :
352 [ - + # # ]: 1 : D("Register EPR path(%s%s,%s) in discovery metadata.", ddimd, path, sha1_name);
353 : 1 : fd = open_fd_from_path(O_CREAT | O_WRONLY | O_TRUNC, 0666, "zxcot -b", 1,
354 : : "%s%s,%s", ddimd, path, sha1_name);
355 [ - + ]: 1 : if (fd == BADFD) {
356 : 0 : perror("open epr for registering");
357 : 0 : ERR("Failed to open file for writing: sha1_name(%s,%s) to service registration", path, sha1_name);
358 : 0 : zx_str_free(cf->ctx, ss);
359 : 0 : return 1;
360 : : }
361 : :
362 : 1 : write_all_fd(fd, ss->s, ss->len);
363 : 1 : zx_str_free(cf->ctx, ss);
364 : 1 : close_file(fd, (const char*)__FUNCTION__);
365 : :
366 [ + - ]: 1 : if (bs_reg) {
367 [ + - ]: 1 : if (verbose)
368 : 1 : fprintf(stderr, "Activating bootstrap %s.all/.bs/%s,%s", duid, path, sha1_name);
369 : :
370 [ + - ]: 1 : if (!dryrun) {
371 : 1 : fd = open_fd_from_path(O_CREAT | O_WRONLY | O_TRUNC, 0666, "zxcot -bs", 1,
372 : : "%s.all/.bs/%s,%s", duid, path, sha1_name);
373 [ - + ]: 1 : if (fd == BADFD) {
374 : 0 : perror("open epr for bootstrap activation");
375 : 0 : ERR("Failed to open file for writing: sha1_name(%s,%s) to bootstrap activation", path, sha1_name);
376 : 0 : return 1;
377 : : }
378 : :
379 : 1 : write_all_fd(fd, "", 0);
380 : 1 : close_file(fd, (const char*)__FUNCTION__);
381 : : }
382 : : } else {
383 [ # # # # ]: 0 : D("You may also want to activate bootstrap by\n touch %s.all/.bs/%s,%s", duid, path, sha1_name);
384 : : }
385 : 1 : return 0;
386 : : }
387 : :
388 : : /* --------------- addmd --------------- */
389 : :
390 : : /*() Add metadata of a partner to the Circle-of-Trust, represented by the CoT dir */
391 : :
392 : : /* Called by: zxcot_main */
393 : : static int zxid_addmd(zxid_conf* cf, char* mdurl, int dry_run, const char* dcot)
394 : 4 : {
395 : : int got, fd;
396 : : char* p;
397 : : zxid_entity* ent;
398 : : struct zx_str* ss;
399 : :
400 [ + + ]: 4 : if (mdurl) {
401 : 2 : ent = zxid_get_meta(cf, mdurl);
402 : : } else {
403 : 2 : read_all_fd(0, buf, sizeof(buf)-1, &got);
404 : 2 : buf[got] = 0;
405 : 2 : p = buf;
406 : 2 : ent = zxid_parse_meta(cf, &p, buf+got);
407 : : }
408 : :
409 [ + + ]: 4 : if (!ent) {
410 : 1 : ERR("***** Parsing metadata failed %d", 0);
411 : 1 : return 1;
412 : : }
413 : :
414 [ + + ]: 6 : for (; ent; ent = ent->n) {
415 : 3 : ss = zx_easy_enc_elem_opt(cf, &ent->ed->gg);
416 [ - + ]: 3 : if (!ss)
417 : 0 : return 2;
418 : :
419 [ + + ]: 3 : if (dry_run) {
420 : 2 : write_all_fd(fdstdout, ss->s, ss->len);
421 : 2 : zx_str_free(cf->ctx, ss);
422 [ + - ]: 2 : if (verbose>1)
423 : 2 : printf("\n\nDry run ent(%s) to %s%s\n", ent->eid, dcot, ent->sha1_name);
424 : 2 : continue;
425 : : }
426 [ + - ]: 1 : if (verbose)
427 : 1 : printf("Writing ent(%s) to %s%s\n", ent->eid, dcot, ent->sha1_name);
428 : :
429 : 1 : fd = open_fd_from_path(O_CREAT | O_WRONLY | O_TRUNC, 0666, "zxcot -a", 1,
430 : : "%s%s", dcot, ent->sha1_name);
431 [ - + ]: 1 : if (fd == BADFD) {
432 : 0 : perror("open metadata for writing metadata to cache");
433 : 0 : ERR("Failed to open file for writing: sha1_name(%s) to metadata cache", ent->sha1_name);
434 : 0 : zx_str_free(cf->ctx, ss);
435 : 0 : return 1;
436 : : }
437 : :
438 : 1 : write_all_fd(fd, ss->s, ss->len);
439 : 1 : zx_str_free(cf->ctx, ss);
440 : 1 : close_file(fd, (const char*)__FUNCTION__);
441 : : }
442 : 3 : return 0;
443 : : }
444 : :
445 : : /* --------------- genmd --------------- */
446 : :
447 : : /*() Generate our own metadata */
448 : :
449 : : /* Called by: zxcot_main */
450 : : static int zxid_genmd(zxid_conf* cf, int dry_run, const char* dcot)
451 : 3 : {
452 : : zxid_cgi cgi;
453 : 3 : struct zx_str* meta = zxid_sp_meta(cf, &cgi);
454 : 3 : ZERO(&cgi, sizeof(cgi));
455 : 3 : printf("%.*s", meta->len, meta->s);
456 : 3 : return 0;
457 : : }
458 : :
459 : : /* --------------- lscot --------------- */
460 : :
461 : : /*() Print a line of Circle-of-Trust listing */
462 : :
463 : : /* Called by: zxid_lscot x2 */
464 : : static int zxid_lscot_line(zxid_conf* cf, int col_swap, const char* dcot, const char* den)
465 : 98 : {
466 : : zxid_entity* ent;
467 : : char* p;
468 : 98 : int got = read_all(ZXID_MAX_MD, buf, "zxcot line", 1, "%s%s", dcot, den);
469 [ + + ]: 98 : if (!got) {
470 : 1 : ERR("Zero data in file(%s%s). If cot directory does not exist consider running zxmkdirs.sh", dcot, den);
471 : 1 : return 1;
472 : : }
473 : 97 : p = buf;
474 : 97 : ent = zxid_parse_meta(cf, &p, buf+got);
475 [ - + ]: 97 : if (!ent) {
476 : 0 : ERR("***** Parsing metadata failed for(%s%s)", dcot, den);
477 : 0 : return 2;
478 : : }
479 [ + + ]: 291 : while (ent) {
480 [ + + + ]: 97 : switch (col_swap) {
481 [ + + ]: 37 : case 1: printf("%-50s %s%s %s\n", ent->eid, dcot, den, STRNULLCHKD(ent->dpy_name)); break;
482 : 20 : case 2: printf("%s\n", ent->eid); break;
483 [ + + ]: 40 : default: printf("%s%s %-50s %s\n", dcot, den, ent->eid, STRNULLCHKD(ent->dpy_name));
484 : : }
485 [ + - + + ]: 97 : if (strcmp(*den?den:dcot, ent->sha1_name))
486 [ + - ]: 4 : fprintf(stderr, "Filename(%s) does not match sha1_name(%s)\n", *den?den:dcot, ent->sha1_name);
487 : 97 : ent = ent->n;
488 : : }
489 : 97 : return 0;
490 : : }
491 : :
492 : : /*() List the contents of the Circle-of-Trust, represented by the CoT directory,
493 : : * in various formats. */
494 : :
495 : : /* Called by: zxcot_main */
496 : : static int zxid_lscot(zxid_conf* cf, int col_swap, const char* dcot)
497 : 6 : {
498 : : int got, ret;
499 : : char* p;
500 : : DIR* dir;
501 : : struct dirent* de;
502 : :
503 : 6 : dir = opendir(dcot);
504 [ + + ]: 6 : if (!dir) {
505 : 1 : perror("opendir for /var/zxid/cot (or other if configured) for loading cot cache");
506 [ - + # # ]: 1 : D("failed path(%s)", dcot);
507 : :
508 : 1 : got = strlen(dcot);
509 : 1 : p = ZX_ALLOC(cf->ctx, got+1);
510 : 1 : memcpy(p, dcot, got-1);
511 : 1 : p[got-1] = 0; /* chop off / */
512 : 1 : got = zxid_lscot_line(cf, col_swap, p, "");
513 : 1 : ZX_FREE(cf->ctx, p);
514 : 1 : return got;
515 : : }
516 : :
517 [ + + ]: 121 : while (de = readdir(dir)) {
518 [ + + + + ]: 111 : if (de->d_name[0] == '.' || de->d_name[strlen(de->d_name)-1] == '~')
519 : : continue;
520 : 97 : ret = zxid_lscot_line(cf, col_swap, dcot, de->d_name);
521 [ - + # # ]: 97 : if (!ONE_OF_2(ret, 0, 2))
522 : 0 : return ret;
523 : : }
524 : 5 : return 0;
525 : : }
526 : :
527 : : /* ============== MAIN ============ */
528 : :
529 : : #ifndef zxcot_main
530 : : #define zxcot_main main
531 : : #endif
532 : :
533 : : /*() Circle of Trust management tool */
534 : :
535 : : /* Called by: */
536 : : int zxcot_main(int argc, char** argv, char** env)
537 : 20 : {
538 : 20 : strncpy(zx_instance, "\tzxcot", sizeof(zx_instance));
539 : 20 : cf = zxid_new_conf_to_cf(0);
540 : :
541 : 20 : opt(&argc, &argv, &env);
542 : :
543 [ + + ]: 16 : if (entid) {
544 : : char sha1_name[28];
545 : 1 : sha1_safe_base64(sha1_name, strlen(entid), entid);
546 : 1 : sha1_name[27] = 0;
547 : 1 : printf("%s\n", sha1_name);
548 : 1 : return 0;
549 : : }
550 : :
551 [ + + ]: 15 : if (addmd)
552 : 4 : return zxid_addmd(cf, mdurl, dryrun, cotdir);
553 : :
554 [ + + ]: 11 : if (regsvc)
555 : 2 : return zxid_reg_svc(cf, regbs, dryrun, dimddir, uiddir);
556 : :
557 [ + + ]: 9 : if (genmd)
558 : 3 : return zxid_genmd(cf, dryrun, cotdir);
559 : :
560 : 6 : return zxid_lscot(cf, swap, cotdir);
561 : : }
562 : :
563 : : /* EOF -- zxcot.c */
|