xref: /freebsd/crypto/krb5/src/lib/krb5/krb/t_walk_rtree.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * t_walk_rtree.c --- test krb5_walk_realm_tree
4*7f2fe78bSCy Schubert  */
5*7f2fe78bSCy Schubert 
6*7f2fe78bSCy Schubert #include "k5-int.h"
7*7f2fe78bSCy Schubert #include <stdio.h>
8*7f2fe78bSCy Schubert #include "com_err.h"
9*7f2fe78bSCy Schubert 
10*7f2fe78bSCy Schubert int
main(int argc,char ** argv)11*7f2fe78bSCy Schubert main(int argc, char **argv)
12*7f2fe78bSCy Schubert {
13*7f2fe78bSCy Schubert     krb5_data client, server;
14*7f2fe78bSCy Schubert     char    realm_branch_char = '.';
15*7f2fe78bSCy Schubert     krb5_principal *tree, *p;
16*7f2fe78bSCy Schubert     char *name;
17*7f2fe78bSCy Schubert     krb5_error_code retval;
18*7f2fe78bSCy Schubert     krb5_context context;
19*7f2fe78bSCy Schubert 
20*7f2fe78bSCy Schubert     krb5_init_context(&context);
21*7f2fe78bSCy Schubert 
22*7f2fe78bSCy Schubert     if (argc < 3 || argc > 4) {
23*7f2fe78bSCy Schubert         fprintf(stderr,
24*7f2fe78bSCy Schubert                 "Usage: %s client-realm server-realm [sep_char]\n",
25*7f2fe78bSCy Schubert                 argv[0]);
26*7f2fe78bSCy Schubert         exit(99);
27*7f2fe78bSCy Schubert     }
28*7f2fe78bSCy Schubert     client.data = argv[1];
29*7f2fe78bSCy Schubert     client.length = strlen(client.data);
30*7f2fe78bSCy Schubert 
31*7f2fe78bSCy Schubert     server.data = argv[2];
32*7f2fe78bSCy Schubert     server.length = strlen(server.data);
33*7f2fe78bSCy Schubert 
34*7f2fe78bSCy Schubert     if (argc == 4)
35*7f2fe78bSCy Schubert         realm_branch_char = argv[3][0];
36*7f2fe78bSCy Schubert 
37*7f2fe78bSCy Schubert     retval = krb5_walk_realm_tree(context, &client, &server, &tree,
38*7f2fe78bSCy Schubert                                   realm_branch_char);
39*7f2fe78bSCy Schubert     if (retval) {
40*7f2fe78bSCy Schubert         com_err("krb5_walk_realm_tree", retval, " ");
41*7f2fe78bSCy Schubert         exit(1);
42*7f2fe78bSCy Schubert     }
43*7f2fe78bSCy Schubert 
44*7f2fe78bSCy Schubert     for (p = tree; *p; p++) {
45*7f2fe78bSCy Schubert         retval = krb5_unparse_name(context, *p, &name);
46*7f2fe78bSCy Schubert         if (retval) {
47*7f2fe78bSCy Schubert             com_err("krb5_unprase_name", retval, " ");
48*7f2fe78bSCy Schubert             exit(2);
49*7f2fe78bSCy Schubert         }
50*7f2fe78bSCy Schubert         printf("%s\n", name);
51*7f2fe78bSCy Schubert         free(name);
52*7f2fe78bSCy Schubert     }
53*7f2fe78bSCy Schubert 
54*7f2fe78bSCy Schubert     krb5_free_realm_tree(context, tree);
55*7f2fe78bSCy Schubert     krb5_free_context(context);
56*7f2fe78bSCy Schubert 
57*7f2fe78bSCy Schubert     exit(0);
58*7f2fe78bSCy Schubert }
59