1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* This driver routine is used to test many of the standard Kerberos library
* routines.
*/
#include "krb5.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "com_err.h"
void test_string_to_timestamp(ctx, time)
krb5_context ctx;
char *time;
{
krb5_timestamp timestamp;
time_t t;
krb5_error_code retval;
retval = krb5_string_to_timestamp(time, ×tamp);
if (retval) {
com_err("krb5_string_to_timestamp", retval, 0);
return;
}
t = (time_t) timestamp;
printf("Parsed time was %s", ctime(&t));
}
void test_425_conv_principal(ctx, name, inst, realm)
krb5_context ctx;
char *name, *inst, *realm;
{
krb5_error_code retval;
krb5_principal princ;
char *out_name;
retval = krb5_425_conv_principal(ctx, name, inst, realm, &princ);
if (retval) {
com_err("krb5_425_conv_principal", retval, 0);
return;
}
retval = krb5_unparse_name(ctx, princ, &out_name);
if (retval) {
com_err("krb5_unparse_name", retval, 0);
return;
}
printf("425_converted principal(%s, %s, %s): '%s'\n",
name, inst, realm, out_name);
free(out_name);
krb5_free_principal(ctx, princ);
}
void test_parse_name(ctx, name)
krb5_context ctx;
const char *name;
{
krb5_error_code retval;
krb5_principal princ = 0, princ2 = 0;
char *outname = 0;
retval = krb5_parse_name(ctx, name, &princ);
if (retval) {
com_err("krb5_parse_name", retval, 0);
goto fail;
}
retval = krb5_copy_principal(ctx, princ, &princ2);
if (retval) {
com_err("krb5_copy_principal", retval, 0);
goto fail;
}
retval = krb5_unparse_name(ctx, princ2, &outname);
if (retval) {
com_err("krb5_unparse_name", retval, 0);
goto fail;
}
printf("parsed (and unparsed) principal(%s): ", name);
if (strcmp(name, outname) == 0)
printf("MATCH\n");
else
printf("'%s'\n", outname);
fail:
if (outname)
free(outname);
if (princ)
krb5_free_principal(ctx, princ);
if (princ2)
krb5_free_principal(ctx, princ2);
}
void test_set_realm(ctx, name, realm)
krb5_context ctx;
const char *name;
const char *realm;
{
krb5_error_code retval;
krb5_principal princ = 0;
char *outname = 0;
retval = krb5_parse_name(ctx, name, &princ);
if (retval) {
com_err("krb5_parse_name", retval, 0);
goto fail;
}
retval = krb5_set_principal_realm(ctx, princ, realm);
if (retval) {
com_err("krb5_set_principal_realm", retval, 0);
goto fail;
}
retval = krb5_unparse_name(ctx, princ, &outname);
if (retval) {
com_err("krb5_unparse_name", retval, 0);
goto fail;
}
printf("old principal: %s, modified principal: %s\n", name,
outname);
fail:
if (outname)
free(outname);
if (princ)
krb5_free_principal(ctx, princ);
}
void usage(progname)
char *progname;
{
fprintf(stderr, "%s: Usage: %s 425_conv_principal <name> <inst> <realm\n",
progname, progname);
fprintf(stderr, "\t%s parse_name <name>\n", progname);
fprintf(stderr, "\t%s set_realm <name> <realm>\n", progname);
fprintf(stderr, "\t%s string_to_timestamp <time>\n", progname);
exit(1);
}
int
main(argc, argv)
int argc;
char **argv;
{
krb5_context ctx;
krb5_error_code retval;
char *progname;
char *name, *inst, *realm;
retval = krb5_init_context(&ctx);
if (retval) {
fprintf(stderr, "krb5_init_context returned error %ld\n",
retval);
exit(1);
}
progname = argv[0];
/* Parse arguments. */
argc--; argv++;
while (argc) {
if (strcmp(*argv, "425_conv_principal") == 0) {
argc--; argv++;
if (!argc) usage(progname);
name = *argv;
argc--; argv++;
if (!argc) usage(progname);
inst = *argv;
argc--; argv++;
if (!argc) usage(progname);
realm = *argv;
test_425_conv_principal(ctx, name, inst, realm);
} else if (strcmp(*argv, "parse_name") == 0) {
argc--; argv++;
if (!argc) usage(progname);
name = *argv;
test_parse_name(ctx, name);
} else if (strcmp(*argv, "set_realm") == 0) {
argc--; argv++;
if (!argc) usage(progname);
name = *argv;
argc--; argv++;
if (!argc) usage(progname);
realm = *argv;
test_set_realm(ctx, name, realm);
} else if (strcmp(*argv, "string_to_timestamp") == 0) {
argc--; argv++;
if (!argc) usage(progname);
test_string_to_timestamp(ctx, *argv);
}
else
usage(progname);
argc--; argv++;
}
krb5_free_context(ctx);
return 0;
}
|