Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/tests/asn.1/t_trval.c
34890 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/*
3
* Copyright (C) 1992,1993 Trusted Information Systems, Inc.
4
*
5
* Permission to include this software in the Kerberos V5 distribution
6
* was graciously provided by Trusted Information Systems.
7
*
8
* Trusted Information Systems makes no representation about the
9
* suitability of this software for any purpose. It is provided
10
* "as is" without express or implied warranty.
11
*
12
* Copyright (C) 1994 Massachusetts Institute of Technology
13
*
14
* Export of this software from the United States of America may
15
* require a specific license from the United States Government.
16
* It is the responsibility of any person or organization contemplating
17
* export to obtain such a license before exporting.
18
*
19
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
20
* distribute this software and its documentation for any purpose and
21
* without fee is hereby granted, provided that the above copyright
22
* notice appear in all copies and that both that copyright notice and
23
* this permission notice appear in supporting documentation, and that
24
* the name of M.I.T. not be used in advertising or publicity pertaining
25
* to distribution of the software without specific, written prior
26
* permission. Furthermore if you modify this software you must label
27
* your software as modified software and not distribute it in such a
28
* fashion that it might be confused with the original M.I.T. software.
29
* M.I.T. makes no representations about the suitability of
30
* this software for any purpose. It is provided "as is" without express
31
* or implied warranty.
32
*/
33
34
/* Split out from "#ifdef STANDALONE" code previously in trval.c, so
35
that trval.o could be linked into other tests too without the
36
-DSTANDALONE code. */
37
#include "trval.c"
38
39
static void
40
usage(void)
41
{
42
fprintf(stderr, "Usage: trval [--types] [--krb5] [--krb5decode] [--hex] [-notypebytes] [file]\n");
43
exit(1);
44
}
45
46
/*
47
* Returns true if the option was selected. Allow "-option" and
48
* "--option" syntax, since we used to accept only "-option"
49
*/
50
static int
51
check_option(char *word, char *option)
52
{
53
if (word[0] != '-')
54
return 0;
55
if (word[1] == '-')
56
word++;
57
if (strcmp(word+1, option))
58
return 0;
59
return 1;
60
}
61
62
int
63
main(int argc, char **argv)
64
{
65
int optflg = 1;
66
FILE *fp;
67
int r = 0;
68
69
while (--argc > 0) {
70
argv++;
71
if (optflg && *(argv)[0] == '-') {
72
if (check_option(*argv, "help"))
73
usage();
74
else if (check_option(*argv, "types"))
75
print_types = 1;
76
else if (check_option(*argv, "notypes"))
77
print_types = 0;
78
else if (check_option(*argv, "krb5"))
79
print_krb5_types = 1;
80
else if (check_option(*argv, "hex"))
81
do_hex = 1;
82
else if (check_option(*argv, "notypebytes"))
83
print_id_and_len = 0;
84
else if (check_option(*argv, "krb5decode")) {
85
print_id_and_len = 0;
86
print_krb5_types = 1;
87
print_types = 1;
88
} else {
89
fprintf(stderr,"trval: unknown option: %s\n", *argv);
90
usage();
91
}
92
} else {
93
optflg = 0;
94
if ((fp = fopen(*argv,"r")) == NULL) {
95
fprintf(stderr,"trval: unable to open %s\n", *argv);
96
continue;
97
}
98
r = trval(fp, stdout);
99
fclose(fp);
100
}
101
}
102
if (optflg) r = trval(stdin, stdout);
103
104
exit(r);
105
}
106
107