1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* tests/shlib/t_loader.c */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert * Copyright (C) 2005 by the Massachusetts Institute of Technology.
5*7f2fe78bSCy Schubert * All rights reserved.
6*7f2fe78bSCy Schubert *
7*7f2fe78bSCy Schubert * Export of this software from the United States of America may
8*7f2fe78bSCy Schubert * require a specific license from the United States Government.
9*7f2fe78bSCy Schubert * It is the responsibility of any person or organization contemplating
10*7f2fe78bSCy Schubert * export to obtain such a license before exporting.
11*7f2fe78bSCy Schubert *
12*7f2fe78bSCy Schubert * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*7f2fe78bSCy Schubert * distribute this software and its documentation for any purpose and
14*7f2fe78bSCy Schubert * without fee is hereby granted, provided that the above copyright
15*7f2fe78bSCy Schubert * notice appear in all copies and that both that copyright notice and
16*7f2fe78bSCy Schubert * this permission notice appear in supporting documentation, and that
17*7f2fe78bSCy Schubert * the name of M.I.T. not be used in advertising or publicity pertaining
18*7f2fe78bSCy Schubert * to distribution of the software without specific, written prior
19*7f2fe78bSCy Schubert * permission. Furthermore if you modify this software you must label
20*7f2fe78bSCy Schubert * your software as modified software and not distribute it in such a
21*7f2fe78bSCy Schubert * fashion that it might be confused with the original M.I.T. software.
22*7f2fe78bSCy Schubert * M.I.T. makes no representations about the suitability of
23*7f2fe78bSCy Schubert * this software for any purpose. It is provided "as is" without express
24*7f2fe78bSCy Schubert * or implied warranty.
25*7f2fe78bSCy Schubert */
26*7f2fe78bSCy Schubert
27*7f2fe78bSCy Schubert #include "k5-platform.h"
28*7f2fe78bSCy Schubert #include "krb5.h"
29*7f2fe78bSCy Schubert #include "gssapi/gssapi.h"
30*7f2fe78bSCy Schubert #define HAVE_DLOPEN 1
31*7f2fe78bSCy Schubert
32*7f2fe78bSCy Schubert static int verbose = 1;
33*7f2fe78bSCy Schubert
34*7f2fe78bSCy Schubert #ifdef HAVE_DLFCN_H
35*7f2fe78bSCy Schubert # include <dlfcn.h>
36*7f2fe78bSCy Schubert #endif
37*7f2fe78bSCy Schubert /* Solaris man page recommends link.h too */
38*7f2fe78bSCy Schubert
39*7f2fe78bSCy Schubert /* lazy = 1 means resolve symbols later, 0 means now; any
40*7f2fe78bSCy Schubert other flags we should be testing? On Windows, maybe?
41*7f2fe78bSCy Schubert
42*7f2fe78bSCy Schubert Return value is the library handle. On error, print a message and
43*7f2fe78bSCy Schubert exit. */
44*7f2fe78bSCy Schubert #define do_open(LIB,REV,FLAGS) do_open_1(LIB,REV,FLAGS,__LINE__)
45*7f2fe78bSCy Schubert static void *do_open_1(const char *libname, const char *rev, int lazy, int line);
46*7f2fe78bSCy Schubert
47*7f2fe78bSCy Schubert /* Look up a function symbol in the library and return a pointer.
48*7f2fe78bSCy Schubert
49*7f2fe78bSCy Schubert The return value may need casting to the correct type. On error,
50*7f2fe78bSCy Schubert print a message and exit. */
51*7f2fe78bSCy Schubert static void *get_sym_1(void *libhandle, const char *sym, int line);
52*7f2fe78bSCy Schubert #define get_sym(LIB, NAME) get_sym_1(LIB, NAME, __LINE__)
53*7f2fe78bSCy Schubert #define GET_FSYM(TYPE, LIB, NAME) ((TYPE) get_sym(LIB, NAME))
54*7f2fe78bSCy Schubert #define get_gfun(LIB, NAME) ((OM_uint32 KRB5_CALLCONV(*)()) get_sym(LIB, NAME))
55*7f2fe78bSCy Schubert
56*7f2fe78bSCy Schubert /* Close dynamically-opened library.
57*7f2fe78bSCy Schubert
58*7f2fe78bSCy Schubert If the OS reports an error in doing so, print a message and
59*7f2fe78bSCy Schubert exit. */
60*7f2fe78bSCy Schubert #define do_close(X) do_close_1(X, __LINE__)
61*7f2fe78bSCy Schubert static void do_close_1(void *libhandle, int line);
62*7f2fe78bSCy Schubert
63*7f2fe78bSCy Schubert #ifdef HAVE_DLOPEN
64*7f2fe78bSCy Schubert
65*7f2fe78bSCy Schubert #ifdef _AIX
66*7f2fe78bSCy Schubert # define SHLIB_SUFFIX ".a"
67*7f2fe78bSCy Schubert #else
68*7f2fe78bSCy Schubert # define SHLIB_SUFFIX ".so"
69*7f2fe78bSCy Schubert #endif
70*7f2fe78bSCy Schubert
71*7f2fe78bSCy Schubert #define HORIZ 25
72*7f2fe78bSCy Schubert
do_open_1(const char * libname,const char * rev,int lazy,int line)73*7f2fe78bSCy Schubert static void *do_open_1(const char *libname, const char *rev,
74*7f2fe78bSCy Schubert int lazy, int line)
75*7f2fe78bSCy Schubert {
76*7f2fe78bSCy Schubert void *p;
77*7f2fe78bSCy Schubert char *namebuf;
78*7f2fe78bSCy Schubert int r;
79*7f2fe78bSCy Schubert
80*7f2fe78bSCy Schubert if (verbose)
81*7f2fe78bSCy Schubert printf("from line %d: do_open(%s)...%*s", line, libname,
82*7f2fe78bSCy Schubert HORIZ-strlen(libname), "");
83*7f2fe78bSCy Schubert #ifdef _AIX
84*7f2fe78bSCy Schubert r = asprintf(&namebuf, "lib%s%s", libname, SHLIB_SUFFIX);
85*7f2fe78bSCy Schubert #else
86*7f2fe78bSCy Schubert r = asprintf(&namebuf, "lib%s%s(shr.o.%s)", libname, SHLIB_SUFFIX, rev);
87*7f2fe78bSCy Schubert #endif
88*7f2fe78bSCy Schubert if (r < 0) {
89*7f2fe78bSCy Schubert perror("asprintf");
90*7f2fe78bSCy Schubert exit(1);
91*7f2fe78bSCy Schubert }
92*7f2fe78bSCy Schubert
93*7f2fe78bSCy Schubert #ifndef RTLD_MEMBER
94*7f2fe78bSCy Schubert #define RTLD_MEMBER 0
95*7f2fe78bSCy Schubert #endif
96*7f2fe78bSCy Schubert p = dlopen(namebuf, (lazy ? RTLD_LAZY : RTLD_NOW) | RTLD_MEMBER);
97*7f2fe78bSCy Schubert if (p == 0) {
98*7f2fe78bSCy Schubert fprintf(stderr, "dlopen of %s failed: %s\n", namebuf, dlerror());
99*7f2fe78bSCy Schubert exit(1);
100*7f2fe78bSCy Schubert }
101*7f2fe78bSCy Schubert free(namebuf);
102*7f2fe78bSCy Schubert if (verbose)
103*7f2fe78bSCy Schubert printf("done: %p\n", p);
104*7f2fe78bSCy Schubert return p;
105*7f2fe78bSCy Schubert }
106*7f2fe78bSCy Schubert
107*7f2fe78bSCy Schubert #define SYM_PREFIX ""
get_sym_1(void * libhandle,const char * symname,int line)108*7f2fe78bSCy Schubert static void *get_sym_1(void *libhandle, const char *symname, int line)
109*7f2fe78bSCy Schubert {
110*7f2fe78bSCy Schubert void *s;
111*7f2fe78bSCy Schubert
112*7f2fe78bSCy Schubert /* Bah. Fix this later, if we care. */
113*7f2fe78bSCy Schubert assert(strlen(SYM_PREFIX) == 0);
114*7f2fe78bSCy Schubert
115*7f2fe78bSCy Schubert if (verbose)
116*7f2fe78bSCy Schubert printf("from line %d: get_sym(%s)...%*s", line, symname,
117*7f2fe78bSCy Schubert HORIZ-strlen(symname), "");
118*7f2fe78bSCy Schubert
119*7f2fe78bSCy Schubert s = dlsym(libhandle, symname);
120*7f2fe78bSCy Schubert if (s == 0) {
121*7f2fe78bSCy Schubert fprintf(stderr, "symbol %s not found\n", symname);
122*7f2fe78bSCy Schubert exit(1);
123*7f2fe78bSCy Schubert }
124*7f2fe78bSCy Schubert if (verbose)
125*7f2fe78bSCy Schubert printf("done: %p\n", s);
126*7f2fe78bSCy Schubert return s;
127*7f2fe78bSCy Schubert }
128*7f2fe78bSCy Schubert
do_close_1(void * libhandle,int line)129*7f2fe78bSCy Schubert static void do_close_1(void *libhandle, int line)
130*7f2fe78bSCy Schubert {
131*7f2fe78bSCy Schubert if (verbose) {
132*7f2fe78bSCy Schubert char pbuf[3*sizeof(libhandle)+4];
133*7f2fe78bSCy Schubert snprintf(pbuf, sizeof(pbuf), "%p", libhandle);
134*7f2fe78bSCy Schubert printf("from line %d: do_close(%s)...%*s", line, pbuf,
135*7f2fe78bSCy Schubert HORIZ-1-strlen(pbuf), "");
136*7f2fe78bSCy Schubert }
137*7f2fe78bSCy Schubert if (dlclose(libhandle) != 0) {
138*7f2fe78bSCy Schubert fprintf(stderr, "dlclose failed: %s\n", dlerror());
139*7f2fe78bSCy Schubert exit(1);
140*7f2fe78bSCy Schubert }
141*7f2fe78bSCy Schubert if (verbose)
142*7f2fe78bSCy Schubert printf("done\n");
143*7f2fe78bSCy Schubert }
144*7f2fe78bSCy Schubert
145*7f2fe78bSCy Schubert #elif defined _WIN32
146*7f2fe78bSCy Schubert
do_open(const char * libname,int lazy)147*7f2fe78bSCy Schubert static void *do_open(const char *libname, int lazy)
148*7f2fe78bSCy Schubert {
149*7f2fe78bSCy Schubert /* To be written? */
150*7f2fe78bSCy Schubert abort();
151*7f2fe78bSCy Schubert }
152*7f2fe78bSCy Schubert
get_sym(void * libhandle,const char * symname)153*7f2fe78bSCy Schubert static void *get_sym(void *libhandle, const char *symname)
154*7f2fe78bSCy Schubert {
155*7f2fe78bSCy Schubert abort();
156*7f2fe78bSCy Schubert }
157*7f2fe78bSCy Schubert
do_close(void * libhandle)158*7f2fe78bSCy Schubert static void do_close(void *libhandle)
159*7f2fe78bSCy Schubert {
160*7f2fe78bSCy Schubert abort();
161*7f2fe78bSCy Schubert }
162*7f2fe78bSCy Schubert
163*7f2fe78bSCy Schubert #else
164*7f2fe78bSCy Schubert
do_open(const char * libname,int lazy)165*7f2fe78bSCy Schubert static void *do_open(const char *libname, int lazy)
166*7f2fe78bSCy Schubert {
167*7f2fe78bSCy Schubert printf("don't know how to do dynamic loading here, punting\n");
168*7f2fe78bSCy Schubert exit(0);
169*7f2fe78bSCy Schubert }
170*7f2fe78bSCy Schubert
get_sym(void * libhandle,const char * symname)171*7f2fe78bSCy Schubert static void *get_sym(void *libhandle, const char *symname)
172*7f2fe78bSCy Schubert {
173*7f2fe78bSCy Schubert abort();
174*7f2fe78bSCy Schubert }
175*7f2fe78bSCy Schubert
do_close(void * libhandle)176*7f2fe78bSCy Schubert static void do_close(void *libhandle)
177*7f2fe78bSCy Schubert {
178*7f2fe78bSCy Schubert abort();
179*7f2fe78bSCy Schubert }
180*7f2fe78bSCy Schubert
181*7f2fe78bSCy Schubert #endif
182*7f2fe78bSCy Schubert
main()183*7f2fe78bSCy Schubert int main()
184*7f2fe78bSCy Schubert {
185*7f2fe78bSCy Schubert void *celib, *k5lib, *gsslib, *celib2;
186*7f2fe78bSCy Schubert
187*7f2fe78bSCy Schubert (void) setvbuf(stdout, 0, _IONBF, 0);
188*7f2fe78bSCy Schubert
189*7f2fe78bSCy Schubert celib = do_open("com_err", "3.0", 0);
190*7f2fe78bSCy Schubert k5lib = do_open("krb5", "3.2", 0);
191*7f2fe78bSCy Schubert gsslib = do_open("gssapi_krb5", "2.2", 0);
192*7f2fe78bSCy Schubert celib2 = do_open("com_err", "3.0", 0);
193*7f2fe78bSCy Schubert do_close(celib2);
194*7f2fe78bSCy Schubert {
195*7f2fe78bSCy Schubert typedef krb5_error_code KRB5_CALLCONV (*ict)(krb5_context *);
196*7f2fe78bSCy Schubert typedef void KRB5_CALLCONV (*fct)(krb5_context);
197*7f2fe78bSCy Schubert
198*7f2fe78bSCy Schubert ict init_context = (ict) get_sym(k5lib, "krb5_init_context");
199*7f2fe78bSCy Schubert fct free_context = (fct) get_sym(k5lib, "krb5_free_context");
200*7f2fe78bSCy Schubert krb5_context ctx;
201*7f2fe78bSCy Schubert krb5_error_code err;
202*7f2fe78bSCy Schubert
203*7f2fe78bSCy Schubert #define CALLING(S) (verbose ? printf("at line %d: calling %s...%*s", __LINE__, #S, (int)(HORIZ+1-strlen(#S)), "") : 0)
204*7f2fe78bSCy Schubert #define DONE() (verbose ? printf("done\n") : 0)
205*7f2fe78bSCy Schubert
206*7f2fe78bSCy Schubert CALLING(krb5_init_context);
207*7f2fe78bSCy Schubert err = init_context(&ctx);
208*7f2fe78bSCy Schubert DONE();
209*7f2fe78bSCy Schubert if (err) {
210*7f2fe78bSCy Schubert fprintf(stderr, "error 0x%lx initializing context\n",
211*7f2fe78bSCy Schubert (unsigned long) err);
212*7f2fe78bSCy Schubert exit(1);
213*7f2fe78bSCy Schubert }
214*7f2fe78bSCy Schubert CALLING(krb5_free_context);
215*7f2fe78bSCy Schubert free_context(ctx);
216*7f2fe78bSCy Schubert DONE();
217*7f2fe78bSCy Schubert }
218*7f2fe78bSCy Schubert celib2 = do_open("com_err", "3.0", 0);
219*7f2fe78bSCy Schubert do_close(celib);
220*7f2fe78bSCy Schubert do_close(k5lib);
221*7f2fe78bSCy Schubert do_close(celib2);
222*7f2fe78bSCy Schubert do_close(gsslib);
223*7f2fe78bSCy Schubert
224*7f2fe78bSCy Schubert /* Test gssapi_krb5 without having loaded anything else. */
225*7f2fe78bSCy Schubert gsslib = do_open("gssapi_krb5", "2.2", 1);
226*7f2fe78bSCy Schubert {
227*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*init_sec_context)(OM_uint32 *, gss_cred_id_t,
228*7f2fe78bSCy Schubert gss_ctx_id_t *, gss_name_t,
229*7f2fe78bSCy Schubert gss_OID,
230*7f2fe78bSCy Schubert OM_uint32, OM_uint32,
231*7f2fe78bSCy Schubert gss_channel_bindings_t,
232*7f2fe78bSCy Schubert gss_buffer_t, gss_OID *,
233*7f2fe78bSCy Schubert gss_buffer_t,
234*7f2fe78bSCy Schubert OM_uint32 *, OM_uint32 *)
235*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_init_sec_context");
236*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*import_name)(OM_uint32 *, gss_buffer_t,
237*7f2fe78bSCy Schubert gss_OID, gss_name_t *)
238*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_import_name");
239*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*release_buffer)(OM_uint32 *, gss_buffer_t)
240*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_release_buffer");
241*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*release_name)(OM_uint32 *, gss_name_t *)
242*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_release_name");
243*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*delete_sec_context)(OM_uint32 *,
244*7f2fe78bSCy Schubert gss_ctx_id_t *,
245*7f2fe78bSCy Schubert gss_buffer_t)
246*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_delete_sec_context");
247*7f2fe78bSCy Schubert
248*7f2fe78bSCy Schubert OM_uint32 gmaj, gmin;
249*7f2fe78bSCy Schubert OM_uint32 retflags;
250*7f2fe78bSCy Schubert gss_ctx_id_t gctx = GSS_C_NO_CONTEXT;
251*7f2fe78bSCy Schubert gss_buffer_desc token;
252*7f2fe78bSCy Schubert gss_name_t target;
253*7f2fe78bSCy Schubert static gss_buffer_desc target_name_buf = {
254*7f2fe78bSCy Schubert 9, "x@mit.edu"
255*7f2fe78bSCy Schubert };
256*7f2fe78bSCy Schubert static gss_OID_desc service_name = {
257*7f2fe78bSCy Schubert 10, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"
258*7f2fe78bSCy Schubert };
259*7f2fe78bSCy Schubert
260*7f2fe78bSCy Schubert CALLING(gss_import_name);
261*7f2fe78bSCy Schubert gmaj = import_name(&gmin, &target_name_buf, &service_name, &target);
262*7f2fe78bSCy Schubert DONE();
263*7f2fe78bSCy Schubert if (gmaj != GSS_S_COMPLETE) {
264*7f2fe78bSCy Schubert fprintf(stderr,
265*7f2fe78bSCy Schubert "import_name reports error major 0x%lx minor 0x%lx(%ld)\n",
266*7f2fe78bSCy Schubert (unsigned long) gmaj, (unsigned long) gmin,
267*7f2fe78bSCy Schubert (signed long) gmin);
268*7f2fe78bSCy Schubert exit(1);
269*7f2fe78bSCy Schubert }
270*7f2fe78bSCy Schubert /* This will probably get different errors, depending on
271*7f2fe78bSCy Schubert whether we have tickets at the time. Doesn't matter much,
272*7f2fe78bSCy Schubert we're ignoring the error and testing whether we're doing
273*7f2fe78bSCy Schubert cleanup properly. (Though the internal cleanup needed in
274*7f2fe78bSCy Schubert the two cases might be different.) */
275*7f2fe78bSCy Schubert CALLING(gss_init_sec_context);
276*7f2fe78bSCy Schubert gmaj = init_sec_context(&gmin, GSS_C_NO_CREDENTIAL, &gctx, target,
277*7f2fe78bSCy Schubert GSS_C_NULL_OID, 0, 0, NULL, GSS_C_NO_BUFFER,
278*7f2fe78bSCy Schubert NULL, &token, &retflags, NULL);
279*7f2fe78bSCy Schubert DONE();
280*7f2fe78bSCy Schubert /* Ignore success/failure indication. */
281*7f2fe78bSCy Schubert if (token.length) {
282*7f2fe78bSCy Schubert CALLING(gss_release_buffer);
283*7f2fe78bSCy Schubert release_buffer(&gmin, &token);
284*7f2fe78bSCy Schubert DONE();
285*7f2fe78bSCy Schubert }
286*7f2fe78bSCy Schubert CALLING(gss_release_name);
287*7f2fe78bSCy Schubert release_name(&gmin, &target);
288*7f2fe78bSCy Schubert DONE();
289*7f2fe78bSCy Schubert if (gctx != GSS_C_NO_CONTEXT) {
290*7f2fe78bSCy Schubert CALLING(gss_delete_sec_context);
291*7f2fe78bSCy Schubert delete_sec_context(&gmin, gctx, GSS_C_NO_BUFFER);
292*7f2fe78bSCy Schubert DONE();
293*7f2fe78bSCy Schubert }
294*7f2fe78bSCy Schubert }
295*7f2fe78bSCy Schubert do_close(gsslib);
296*7f2fe78bSCy Schubert
297*7f2fe78bSCy Schubert /* Test gssapi_krb5 with com_err already loaded, then unload
298*7f2fe78bSCy Schubert com_err first. */
299*7f2fe78bSCy Schubert celib = do_open("com_err", "3.0", 1);
300*7f2fe78bSCy Schubert gsslib = do_open("gssapi_krb5", "2.2", 1);
301*7f2fe78bSCy Schubert {
302*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*init_sec_context)(OM_uint32 *, gss_cred_id_t,
303*7f2fe78bSCy Schubert gss_ctx_id_t *, gss_name_t,
304*7f2fe78bSCy Schubert gss_OID,
305*7f2fe78bSCy Schubert OM_uint32, OM_uint32,
306*7f2fe78bSCy Schubert gss_channel_bindings_t,
307*7f2fe78bSCy Schubert gss_buffer_t, gss_OID *,
308*7f2fe78bSCy Schubert gss_buffer_t,
309*7f2fe78bSCy Schubert OM_uint32 *, OM_uint32 *)
310*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_init_sec_context");
311*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*import_name)(OM_uint32 *, gss_buffer_t,
312*7f2fe78bSCy Schubert gss_OID, gss_name_t *)
313*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_import_name");
314*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*release_buffer)(OM_uint32 *, gss_buffer_t)
315*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_release_buffer");
316*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*release_name)(OM_uint32 *, gss_name_t *)
317*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_release_name");
318*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV (*delete_sec_context)(OM_uint32 *,
319*7f2fe78bSCy Schubert gss_ctx_id_t *,
320*7f2fe78bSCy Schubert gss_buffer_t)
321*7f2fe78bSCy Schubert = get_gfun(gsslib, "gss_delete_sec_context");
322*7f2fe78bSCy Schubert
323*7f2fe78bSCy Schubert OM_uint32 gmaj, gmin;
324*7f2fe78bSCy Schubert OM_uint32 retflags;
325*7f2fe78bSCy Schubert gss_ctx_id_t gctx = GSS_C_NO_CONTEXT;
326*7f2fe78bSCy Schubert gss_buffer_desc token;
327*7f2fe78bSCy Schubert gss_name_t target;
328*7f2fe78bSCy Schubert static gss_buffer_desc target_name_buf = {
329*7f2fe78bSCy Schubert 9, "x@mit.edu"
330*7f2fe78bSCy Schubert };
331*7f2fe78bSCy Schubert static gss_OID_desc service_name = {
332*7f2fe78bSCy Schubert 10, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"
333*7f2fe78bSCy Schubert };
334*7f2fe78bSCy Schubert
335*7f2fe78bSCy Schubert CALLING(gss_import_name);
336*7f2fe78bSCy Schubert gmaj = import_name(&gmin, &target_name_buf, &service_name, &target);
337*7f2fe78bSCy Schubert DONE();
338*7f2fe78bSCy Schubert if (gmaj != GSS_S_COMPLETE) {
339*7f2fe78bSCy Schubert fprintf(stderr,
340*7f2fe78bSCy Schubert "import_name reports error major 0x%lx minor 0x%lx(%ld)\n",
341*7f2fe78bSCy Schubert (unsigned long) gmaj, (unsigned long) gmin,
342*7f2fe78bSCy Schubert (signed long) gmin);
343*7f2fe78bSCy Schubert exit(1);
344*7f2fe78bSCy Schubert }
345*7f2fe78bSCy Schubert /* This will probably get different errors, depending on
346*7f2fe78bSCy Schubert whether we have tickets at the time. Doesn't matter much,
347*7f2fe78bSCy Schubert we're ignoring the error and testing whether we're doing
348*7f2fe78bSCy Schubert cleanup properly. (Though the internal cleanup needed in
349*7f2fe78bSCy Schubert the two cases might be different.) */
350*7f2fe78bSCy Schubert CALLING(gss_init_sec_context);
351*7f2fe78bSCy Schubert gmaj = init_sec_context(&gmin, GSS_C_NO_CREDENTIAL, &gctx, target,
352*7f2fe78bSCy Schubert GSS_C_NULL_OID, 0, 0, NULL, GSS_C_NO_BUFFER,
353*7f2fe78bSCy Schubert NULL, &token, &retflags, NULL);
354*7f2fe78bSCy Schubert DONE();
355*7f2fe78bSCy Schubert /* Ignore success/failure indication. */
356*7f2fe78bSCy Schubert if (token.length) {
357*7f2fe78bSCy Schubert CALLING(gss_release_buffer);
358*7f2fe78bSCy Schubert release_buffer(&gmin, &token);
359*7f2fe78bSCy Schubert DONE();
360*7f2fe78bSCy Schubert }
361*7f2fe78bSCy Schubert CALLING(gss_release_name);
362*7f2fe78bSCy Schubert release_name(&gmin, &target);
363*7f2fe78bSCy Schubert DONE();
364*7f2fe78bSCy Schubert if (gctx != GSS_C_NO_CONTEXT) {
365*7f2fe78bSCy Schubert CALLING(gss_delete_sec_context);
366*7f2fe78bSCy Schubert delete_sec_context(&gmin, gctx, GSS_C_NO_BUFFER);
367*7f2fe78bSCy Schubert DONE();
368*7f2fe78bSCy Schubert }
369*7f2fe78bSCy Schubert }
370*7f2fe78bSCy Schubert do_close(celib);
371*7f2fe78bSCy Schubert do_close(gsslib);
372*7f2fe78bSCy Schubert
373*7f2fe78bSCy Schubert return 0;
374*7f2fe78bSCy Schubert }
375