2 * Copyright (c) 2003-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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"
38 print_time(OM_uint32 time_rec
)
40 if (time_rec
== GSS_C_INDEFINITE
) {
41 printf("cred never expire\n");
43 time_t t
= time_rec
+ time(NULL
);
44 printf("expiration time: %s", ctime(&t
));
49 test_add(gss_cred_id_t cred_handle
)
51 OM_uint32 major_status
, minor_status
;
52 gss_cred_id_t copy_cred
;
55 major_status
= gss_add_cred (&minor_status
,
67 if (GSS_ERROR(major_status
))
68 errx(1, "add_cred failed");
72 major_status
= gss_release_cred(&minor_status
,
74 if (GSS_ERROR(major_status
))
75 errx(1, "release_cred failed");
81 OM_uint32 major_status
, minor_status
;
82 gss_cred_id_t cred_handle
;
85 major_status
= gss_acquire_cred(&minor_status
,
93 if (GSS_ERROR(major_status
))
94 errx(1, "acquire_cred failed");
98 test_add(cred_handle
);
99 test_add(cred_handle
);
100 test_add(cred_handle
);
102 major_status
= gss_release_cred(&minor_status
,
104 if (GSS_ERROR(major_status
))
105 errx(1, "release_cred failed");
109 acquire_cred_service(const char *service
)
111 OM_uint32 major_status
, minor_status
;
112 gss_cred_id_t cred_handle
;
114 gss_buffer_desc name_buffer
;
117 name_buffer
.value
= rk_UNCONST(service
);
118 name_buffer
.length
= strlen(service
);
120 major_status
= gss_import_name(&minor_status
,
122 GSS_C_NT_HOSTBASED_SERVICE
,
124 if (GSS_ERROR(major_status
))
125 errx(1, "import_name failed");
128 major_status
= gss_acquire_cred(&minor_status
,
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
,
143 if (GSS_ERROR(major_status
))
144 errx(1, "release_cred failed");
147 major_status
= gss_release_name(&minor_status
,
149 if (GSS_ERROR(major_status
))
150 errx(1, "release_name failed");
155 main(int argc
, char **argv
)
159 acquire_cred_service("host@xen2-heimdal-linux.lab.it.su.se");