1*0a6a1f1dSLionel Sambuc /* $NetBSD: test_gic.c,v 1.1.1.2 2014/04/24 12:45:51 pettai Exp $ */
2ebfedea0SLionel Sambuc
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc * Copyright (c) 2009 Kungliga Tekniska H�gskolan
5ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc * All rights reserved.
7ebfedea0SLionel Sambuc *
8ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc * are met:
11ebfedea0SLionel Sambuc *
12ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc *
15ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc *
19ebfedea0SLionel Sambuc * 3. Neither the name of KTH nor the names of its contributors may be
20ebfedea0SLionel Sambuc * used to endorse or promote products derived from this software without
21ebfedea0SLionel Sambuc * specific prior written permission.
22ebfedea0SLionel Sambuc *
23ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24ebfedea0SLionel Sambuc * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26ebfedea0SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27ebfedea0SLionel Sambuc * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28ebfedea0SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29ebfedea0SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30ebfedea0SLionel Sambuc * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31ebfedea0SLionel Sambuc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32ebfedea0SLionel Sambuc * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33ebfedea0SLionel Sambuc * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
34ebfedea0SLionel Sambuc
35ebfedea0SLionel Sambuc #include "krb5_locl.h"
36ebfedea0SLionel Sambuc #include <err.h>
37ebfedea0SLionel Sambuc #include <krb5/getarg.h>
38ebfedea0SLionel Sambuc
39ebfedea0SLionel Sambuc static char *password_str;
40ebfedea0SLionel Sambuc
41ebfedea0SLionel Sambuc static krb5_error_code
lr_proc(krb5_context context,krb5_last_req_entry ** e,void * ctx)42ebfedea0SLionel Sambuc lr_proc(krb5_context context, krb5_last_req_entry **e, void *ctx)
43ebfedea0SLionel Sambuc {
44ebfedea0SLionel Sambuc while (e && *e) {
45ebfedea0SLionel Sambuc printf("e type: %d value: %d\n", (*e)->lr_type, (int)(*e)->value);
46ebfedea0SLionel Sambuc e++;
47ebfedea0SLionel Sambuc }
48ebfedea0SLionel Sambuc return 0;
49ebfedea0SLionel Sambuc }
50ebfedea0SLionel Sambuc
51ebfedea0SLionel Sambuc static void
test_get_init_creds(krb5_context context,krb5_principal client)52ebfedea0SLionel Sambuc test_get_init_creds(krb5_context context,
53ebfedea0SLionel Sambuc krb5_principal client)
54ebfedea0SLionel Sambuc {
55ebfedea0SLionel Sambuc krb5_error_code ret;
56ebfedea0SLionel Sambuc krb5_get_init_creds_opt *opt;
57ebfedea0SLionel Sambuc krb5_creds cred;
58ebfedea0SLionel Sambuc
59ebfedea0SLionel Sambuc ret = krb5_get_init_creds_opt_alloc(context, &opt);
60ebfedea0SLionel Sambuc if (ret)
61ebfedea0SLionel Sambuc krb5_err(context, 1, ret, "krb5_get_init_creds_opt_alloc");
62ebfedea0SLionel Sambuc
63ebfedea0SLionel Sambuc
64ebfedea0SLionel Sambuc ret = krb5_get_init_creds_opt_set_process_last_req(context,
65ebfedea0SLionel Sambuc opt,
66ebfedea0SLionel Sambuc lr_proc,
67ebfedea0SLionel Sambuc NULL);
68ebfedea0SLionel Sambuc if (ret)
69ebfedea0SLionel Sambuc krb5_err(context, 1, ret,
70ebfedea0SLionel Sambuc "krb5_get_init_creds_opt_set_process_last_req");
71ebfedea0SLionel Sambuc
72ebfedea0SLionel Sambuc ret = krb5_get_init_creds_password(context,
73ebfedea0SLionel Sambuc &cred,
74ebfedea0SLionel Sambuc client,
75ebfedea0SLionel Sambuc password_str,
76ebfedea0SLionel Sambuc krb5_prompter_posix,
77ebfedea0SLionel Sambuc NULL,
78ebfedea0SLionel Sambuc 0,
79ebfedea0SLionel Sambuc NULL,
80ebfedea0SLionel Sambuc opt);
81ebfedea0SLionel Sambuc if (ret)
82ebfedea0SLionel Sambuc krb5_err(context, 1, ret, "krb5_get_init_creds_password");
83ebfedea0SLionel Sambuc
84ebfedea0SLionel Sambuc krb5_get_init_creds_opt_free(context, opt);
85ebfedea0SLionel Sambuc }
86ebfedea0SLionel Sambuc
87ebfedea0SLionel Sambuc static char *client_str = NULL;
88ebfedea0SLionel Sambuc static int debug_flag = 0;
89ebfedea0SLionel Sambuc static int version_flag = 0;
90ebfedea0SLionel Sambuc static int help_flag = 0;
91ebfedea0SLionel Sambuc
92ebfedea0SLionel Sambuc static struct getargs args[] = {
93ebfedea0SLionel Sambuc {"client", 0, arg_string, &client_str,
94ebfedea0SLionel Sambuc "client principal to use", NULL },
95ebfedea0SLionel Sambuc {"password",0, arg_string, &password_str,
96ebfedea0SLionel Sambuc "password", NULL },
97ebfedea0SLionel Sambuc {"debug", 'd', arg_flag, &debug_flag,
98ebfedea0SLionel Sambuc "turn on debuggin", NULL },
99ebfedea0SLionel Sambuc {"version", 0, arg_flag, &version_flag,
100ebfedea0SLionel Sambuc "print version", NULL },
101ebfedea0SLionel Sambuc {"help", 0, arg_flag, &help_flag,
102ebfedea0SLionel Sambuc NULL, NULL }
103ebfedea0SLionel Sambuc };
104ebfedea0SLionel Sambuc
105ebfedea0SLionel Sambuc static void
usage(int ret)106ebfedea0SLionel Sambuc usage (int ret)
107ebfedea0SLionel Sambuc {
108ebfedea0SLionel Sambuc arg_printusage (args, sizeof(args)/sizeof(*args), NULL, "hostname ...");
109ebfedea0SLionel Sambuc exit (ret);
110ebfedea0SLionel Sambuc }
111ebfedea0SLionel Sambuc
112ebfedea0SLionel Sambuc
113ebfedea0SLionel Sambuc int
main(int argc,char ** argv)114ebfedea0SLionel Sambuc main(int argc, char **argv)
115ebfedea0SLionel Sambuc {
116ebfedea0SLionel Sambuc krb5_context context;
117ebfedea0SLionel Sambuc krb5_error_code ret;
118ebfedea0SLionel Sambuc int optidx = 0, errors = 0;
119ebfedea0SLionel Sambuc krb5_principal client;
120ebfedea0SLionel Sambuc
121ebfedea0SLionel Sambuc setprogname(argv[0]);
122ebfedea0SLionel Sambuc
123ebfedea0SLionel Sambuc if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
124ebfedea0SLionel Sambuc usage(1);
125ebfedea0SLionel Sambuc
126ebfedea0SLionel Sambuc if (help_flag)
127ebfedea0SLionel Sambuc usage (0);
128ebfedea0SLionel Sambuc
129ebfedea0SLionel Sambuc if(version_flag){
130ebfedea0SLionel Sambuc print_version(NULL);
131ebfedea0SLionel Sambuc exit(0);
132ebfedea0SLionel Sambuc }
133ebfedea0SLionel Sambuc
134ebfedea0SLionel Sambuc if(client_str == NULL)
135ebfedea0SLionel Sambuc errx(1, "client is not set");
136ebfedea0SLionel Sambuc
137ebfedea0SLionel Sambuc ret = krb5_init_context(&context);
138ebfedea0SLionel Sambuc if (ret)
139ebfedea0SLionel Sambuc errx (1, "krb5_init_context failed: %d", ret);
140ebfedea0SLionel Sambuc
141ebfedea0SLionel Sambuc ret = krb5_parse_name(context, client_str, &client);
142ebfedea0SLionel Sambuc if (ret)
143ebfedea0SLionel Sambuc krb5_err(context, 1, ret, "krb5_parse_name: %d", ret);
144ebfedea0SLionel Sambuc
145ebfedea0SLionel Sambuc test_get_init_creds(context, client);
146ebfedea0SLionel Sambuc
147ebfedea0SLionel Sambuc krb5_free_context(context);
148ebfedea0SLionel Sambuc
149ebfedea0SLionel Sambuc return errors;
150ebfedea0SLionel Sambuc }
151