Implement gss_wrap_iov, gss_unwrap_iov for CFX type encryption types.
[heimdal.git] / lib / gssapi / krb5 / test_acquire_cred.c
blob7abb35dd9b104d1778ac5549bce4968cfc06ab5e
1 /*
2 * Copyright (c) 2003-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "gsskrb5_locl.h"
35 #include <err.h>
37 static void
38 print_time(OM_uint32 time_rec)
40 if (time_rec == GSS_C_INDEFINITE) {
41 printf("cred never expire\n");
42 } else {
43 time_t t = time_rec + time(NULL);
44 printf("expiration time: %s", ctime(&t));
48 static void
49 test_add(gss_cred_id_t cred_handle)
51 OM_uint32 major_status, minor_status;
52 gss_cred_id_t copy_cred;
53 OM_uint32 time_rec;
55 major_status = gss_add_cred (&minor_status,
56 cred_handle,
57 GSS_C_NO_NAME,
58 GSS_KRB5_MECHANISM,
59 GSS_C_INITIATE,
62 &copy_cred,
63 NULL,
64 &time_rec,
65 NULL);
67 if (GSS_ERROR(major_status))
68 errx(1, "add_cred failed");
70 print_time(time_rec);
72 major_status = gss_release_cred(&minor_status,
73 &copy_cred);
74 if (GSS_ERROR(major_status))
75 errx(1, "release_cred failed");
78 static void
79 copy_cred(void)
81 OM_uint32 major_status, minor_status;
82 gss_cred_id_t cred_handle;
83 OM_uint32 time_rec;
85 major_status = gss_acquire_cred(&minor_status,
86 GSS_C_NO_NAME,
88 NULL,
89 GSS_C_INITIATE,
90 &cred_handle,
91 NULL,
92 &time_rec);
93 if (GSS_ERROR(major_status))
94 errx(1, "acquire_cred failed");
96 print_time(time_rec);
98 test_add(cred_handle);
99 test_add(cred_handle);
100 test_add(cred_handle);
102 major_status = gss_release_cred(&minor_status,
103 &cred_handle);
104 if (GSS_ERROR(major_status))
105 errx(1, "release_cred failed");
108 static void
109 acquire_cred_service(const char *service)
111 OM_uint32 major_status, minor_status;
112 gss_cred_id_t cred_handle;
113 OM_uint32 time_rec;
114 gss_buffer_desc name_buffer;
115 gss_name_t name;
117 name_buffer.value = rk_UNCONST(service);
118 name_buffer.length = strlen(service);
120 major_status = gss_import_name(&minor_status,
121 &name_buffer,
122 GSS_C_NT_HOSTBASED_SERVICE,
123 &name);
124 if (GSS_ERROR(major_status))
125 errx(1, "import_name failed");
128 major_status = gss_acquire_cred(&minor_status,
129 name,
131 NULL,
132 GSS_C_ACCEPT,
133 &cred_handle,
134 NULL,
135 &time_rec);
136 if (GSS_ERROR(major_status))
137 errx(1, "acquire_cred failed");
139 print_time(time_rec);
141 major_status = gss_release_cred(&minor_status,
142 &cred_handle);
143 if (GSS_ERROR(major_status))
144 errx(1, "release_cred failed");
147 major_status = gss_release_name(&minor_status,
148 &name);
149 if (GSS_ERROR(major_status))
150 errx(1, "release_name failed");
155 main(int argc, char **argv)
157 copy_cred();
159 acquire_cred_service("host@xen2-heimdal-linux.lab.it.su.se");
161 return 0;