1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/os/t_trace.c - Test harness for trace.c */
4 * Copyright (C) 2012 by the Massachusetts Institute of Technology.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/types.h>
36 #include "port-sockets.h"
46 kfatal (krb5_error_code err)
48 com_err (prog, err, "- exiting");
53 main (int argc, char *argv[])
61 char *str = "example.data";
62 krb5_octet *oct = (krb5_octet *) str;
63 unsigned int oct_length = strlen(str);
64 struct conn_state conn;
65 struct sockaddr_in *addr_in;
67 struct krb5_key_st key;
68 krb5_checksum checksum;
69 krb5_principal_data principal_data, principal_data2;
70 krb5_principal princ = &principal_data;
71 krb5_pa_data padata, padata2, **padatap;
72 krb5_enctype enctypes[4] = {
73 ENCTYPE_DES3_CBC_SHA, ENCTYPE_ARCFOUR_HMAC_EXP, ENCTYPE_UNKNOWN,
79 p = strrchr (argv[0], '/');
86 fprintf (stderr, "%s: usage: %s\n", prog, prog);
90 err = krb5_init_context (&ctx);
94 krb5int_trace(NULL, NULL);
95 TRACE(ctx, "simple format");
97 TRACE(ctx, "int, in decimal: {int}", i);
98 TRACE(ctx, "long, in decimal: {long}", ln);
100 TRACE(ctx, "const char *, display as C string: {str}", str);
102 TRACE(ctx, "size_t and const char *, as a counted string: {lenstr}",
104 TRACE(ctx, "size_t and const char *, as a counted string: {lenstr}",
106 TRACE(ctx, "size_t and const char *, as hex bytes: {hexlenstr}",
108 TRACE(ctx, "size_t and const char *, as hex bytes: {hexlenstr}",
110 TRACE(ctx, "size_t and const char *, as four-character hex hash: "
111 "{hashlenstr}", s, str);
112 TRACE(ctx, "size_t and const char *, as four-character hex hash: "
113 "{hashlenstr}", 1, NULL);
115 conn.socktype = SOCK_STREAM;
116 addr_in = (struct sockaddr_in *) &conn.addr;
117 addr_in->sin_family = AF_INET;
118 addr_in->sin_addr.s_addr = INADDR_ANY;
119 addr_in->sin_port = htons(88);
120 TRACE(ctx, "struct conn_state *, show socket type, address, port: "
121 "{connstate}", &conn);
122 conn.socktype = SOCK_DGRAM;
123 TRACE(ctx, "struct conn_state *, show socket type, address, port: "
124 "{connstate}", &conn);
125 conn.socktype = SOCK_RDM;
126 addr_in->sin_family = AF_UNSPEC;
127 TRACE(ctx, "struct conn_state *, show socket type, address, port: "
128 "{connstate}", &conn);
129 conn.family = AF_UNSPEC;
130 TRACE(ctx, "struct conn_state *, show socket type, address, port: "
131 "{connstate}", &conn);
134 data.length = strlen(str);
136 TRACE(ctx, "krb5_data *, display as counted string: {data}", &data);
137 TRACE(ctx, "krb5_data *, display as counted string: {data}", NULL);
138 TRACE(ctx, "krb5_data *, display as hex bytes: {hexdata}", &data);
139 TRACE(ctx, "krb5_data *, display as hex bytes: {hexdata}", NULL);
141 TRACE(ctx, "int, display as number/errorstring: {errno}", 0);
142 TRACE(ctx, "int, display as number/errorstring: {errno}", 1);
143 TRACE(ctx, "krb5_error_code, display as number/errorstring: {kerr}", 0);
145 key.keyblock.magic = 0;
146 key.keyblock.enctype = ENCTYPE_UNKNOWN;
147 key.keyblock.length = strlen(str);
148 key.keyblock.contents = (krb5_octet *)str;
152 TRACE(ctx, "const krb5_keyblock *, display enctype and hash of key: "
153 "{keyblock}", &key.keyblock);
154 TRACE(ctx, "const krb5_keyblock *, display enctype and hash of key: "
156 TRACE(ctx, "krb5_key, display enctype and hash of key: {key}", &key);
157 TRACE(ctx, "krb5_key, display enctype and hash of key: {key}", NULL);
160 checksum.checksum_type = -1;
161 checksum.length = oct_length;
162 checksum.contents = oct;
163 TRACE(ctx, "const krb5_checksum *, display cksumtype and hex checksum: "
164 "{cksum}", &checksum);
166 principal_data.magic = 0;
167 principal_data.realm.magic = 0;
168 principal_data.realm.data = "ATHENA.MIT.EDU";
169 principal_data.realm.length = strlen(principal_data.realm.data);
170 principal_data.data = &data;
171 principal_data.length = 0;
172 principal_data.type = KRB5_NT_UNKNOWN;
173 TRACE(ctx, "krb5_principal, unparse and display: {princ}", princ);
174 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_UNKNOWN);
175 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_PRINCIPAL);
176 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_SRV_INST);
177 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_SRV_HST);
178 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_SRV_XHST);
179 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_UID);
180 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_X500_PRINCIPAL);
181 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_SMTP_NAME);
182 TRACE(ctx, "int, krb5_principal type: {ptype}",
183 KRB5_NT_ENTERPRISE_PRINCIPAL);
184 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_WELLKNOWN);
185 TRACE(ctx, "int, krb5_principal type: {ptype}", KRB5_NT_MS_PRINCIPAL);
186 TRACE(ctx, "int, krb5_principal type: {ptype}",
187 KRB5_NT_MS_PRINCIPAL_AND_ID);
188 TRACE(ctx, "int, krb5_principal type: {ptype}",
189 KRB5_NT_ENT_PRINCIPAL_AND_ID);
190 TRACE(ctx, "int, krb5_principal type: {ptype}", -1);
192 padatap = malloc(sizeof(krb5_pa_data *) * 3);
193 padatap[0] = &padata;
194 memcpy(&padata2, &padata, sizeof(padata));
195 padatap[1] = &padata2;
198 padata.pa_type = KRB5_PADATA_NONE;
199 padata.length = oct_length;
200 padata.contents = oct;
201 TRACE(ctx, "krb5_pa_data **, display list of padata type numbers: "
202 "{patypes}", padatap);
203 TRACE(ctx, "krb5_pa_data **, display list of padata type numbers: "
208 TRACE(ctx, "krb5_enctype, display shortest name of enctype: {etype}",
209 ENCTYPE_DES_CBC_CRC);
210 TRACE(ctx, "krb5_enctype *, display list of enctypes: {etypes}", enctypes);
211 TRACE(ctx, "krb5_enctype *, display list of enctypes: {etypes}", NULL);
213 err = krb5_cc_default(ctx, &ccache);
214 TRACE(ctx, "krb5_ccache, display type:name: {ccache}", ccache);
215 krb5_cc_close(ctx, ccache);
217 err = krb5_kt_default(ctx, &keytab);
218 TRACE(ctx, "krb5_keytab, display name: {keytab}", keytab);
219 krb5_kt_close(ctx, keytab);
222 creds.client = &principal_data;
223 memcpy(&principal_data2, &principal_data, sizeof(principal_data));
224 principal_data2.realm.data = "ZEUS.MIT.EDU";
225 principal_data2.realm.length = strlen(principal_data2.realm.data);
226 creds.server = &principal_data2;
227 memcpy(&creds.keyblock, &key.keyblock, sizeof(creds.keyblock));
228 creds.times.authtime = 0;
229 creds.times.starttime = 1;
230 creds.times.endtime = 2;
231 creds.times.renew_till = 3;
232 creds.is_skey = FALSE;
233 creds.ticket_flags = 0;
234 creds.addresses = NULL;
235 creds.ticket.magic = 0;
236 creds.ticket.length = strlen(str);
237 creds.ticket.data = str;
238 creds.second_ticket.magic = 0;
239 creds.second_ticket.length = strlen(str);
240 creds.second_ticket.data = str;
241 creds.authdata = NULL;
242 TRACE(ctx, "krb5_creds *, display clientprinc -> serverprinc: {creds}",
245 krb5_free_context(ctx);