xref: /titanic_44/usr/src/cmd/cmd-inet/usr.bin/ftp/cmds_gss.c (revision d583b39bfb4e2571d3e41097c5c357ffe353ad45)
1 /*
2  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * Copyright (c) 1985, 1989 Regents of the University of California.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *      This product includes software developed by the University of
23  *      California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  */
40 
41 #include "ftp_var.h"
42 #include <gssapi/gssapi.h>
43 #include <gssapi/gssapi_ext.h>
44 
45 void
46 user_gss_error(OM_uint32 maj_stat, OM_uint32 min_stat, char *errstr)
47 {
48 	OM_uint32 gmaj_stat, gmin_stat;
49 	gss_buffer_desc msg;
50 	OM_uint32 msg_ctx = 0;
51 	int display_error = 0;
52 
53 	/* Print the major status error from GSS */
54 	while (!msg_ctx) {
55 	    gmaj_stat = gss_display_status(&gmin_stat, maj_stat,
56 		GSS_C_GSS_CODE, GSS_C_NULL_OID, &msg_ctx, &msg);
57 	    if ((gmaj_stat == GSS_S_COMPLETE)||
58 		(gmaj_stat == GSS_S_CONTINUE_NEEDED)) {
59 		/* display error messages only once */
60 		if ((debug) || (!display_error)) {
61 		    (void) fprintf(stderr, "GSSAPI error major: %s\n",
62 			(char *)msg.value);
63 		    display_error = 1;
64 		}
65 		(void) gss_release_buffer(&gmin_stat, &msg);
66 	    }
67 	    if (gmaj_stat != GSS_S_CONTINUE_NEEDED)
68 		break;
69 	}
70 
71 	/* Print the minor status error from the mech */
72 	msg_ctx = 0;
73 	display_error = 0;
74 	if (min_stat)
75 	    while (!msg_ctx) {
76 		gmaj_stat = gss_display_status(&gmin_stat, min_stat,
77 		    GSS_C_MECH_CODE, GSS_C_NULL_OID, &msg_ctx, &msg);
78 		if ((gmaj_stat == GSS_S_COMPLETE)||
79 		    (gmaj_stat == GSS_S_CONTINUE_NEEDED)) {
80 		    /* display error messages only once */
81 		    if ((!display_error) || (!debug)) {
82 			(void) fprintf(stderr, "GSSAPI error minor: %s\n",
83 			    (char *)msg.value);
84 			display_error = 1;
85 		    }
86 		    (void) gss_release_buffer(&gmin_stat, &msg);
87 		}
88 		if (gmaj_stat != GSS_S_CONTINUE_NEEDED)
89 			break;
90 	    }
91 
92 	if (debug) {
93 	    (void) fprintf(stderr, "GSSAPI error: %s\n", errstr);
94 	}
95 }
96