1 /* $NetBSD: gsstool.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $ */
4 * Copyright (c) 2006 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * 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.
21 * 3. Neither the name of KTH nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
26 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <krb5/roken.h>
42 #include <gssapi/gssapi.h>
43 #include <gssapi/gssapi_krb5.h>
44 #include <gssapi/gssapi_spnego.h>
45 #include <gssapi/gssapi_ntlm.h>
47 #include <krb5/getarg.h>
48 #include <krb5/rtbl.h>
49 #include <gss-commands.h>
52 static int version_flag
= 0;
53 static int help_flag
= 0;
55 static struct getargs args
[] = {
56 {"version", 0, arg_flag
, &version_flag
, "print version", NULL
},
57 {"help", 0, arg_flag
, &help_flag
, NULL
, NULL
}
63 arg_printusage (args
, sizeof(args
)/sizeof(*args
),
64 NULL
, "service@host");
69 #define COL_NAME "Name"
70 #define COL_DESC "Description"
71 #define COL_VALUE "Value"
72 #define COL_MECH "Mech"
73 #define COL_EXPIRE "Expire"
74 #define COL_SASL "SASL"
77 supported_mechanisms(void *argptr
, int argc
, char **argv
)
79 OM_uint32 maj_stat
, min_stat
;
84 maj_stat
= gss_indicate_mechs(&min_stat
, &mechs
);
85 if (maj_stat
!= GSS_S_COMPLETE
)
86 errx(1, "gss_indicate_mechs failed");
88 printf("Supported mechanisms:\n");
92 errx(1, "rtbl_create");
94 rtbl_set_separator(ct
, " ");
95 rtbl_add_column(ct
, COL_OID
, 0);
96 rtbl_add_column(ct
, COL_NAME
, 0);
97 rtbl_add_column(ct
, COL_DESC
, 0);
98 rtbl_add_column(ct
, COL_SASL
, 0);
100 for (i
= 0; i
< mechs
->count
; i
++) {
101 gss_buffer_desc str
, sasl_name
, mech_name
, mech_desc
;
103 maj_stat
= gss_oid_to_str(&min_stat
, &mechs
->elements
[i
], &str
);
104 if (maj_stat
!= GSS_S_COMPLETE
)
105 errx(1, "gss_oid_to_str failed");
107 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
108 (int)str
.length
, (char *)str
.value
);
109 gss_release_buffer(&min_stat
, &str
);
111 (void)gss_inquire_saslname_for_mech(&min_stat
,
117 rtbl_add_column_entryv(ct
, COL_NAME
, "%.*s",
118 (int)mech_name
.length
, (char *)mech_name
.value
);
119 rtbl_add_column_entryv(ct
, COL_DESC
, "%.*s",
120 (int)mech_desc
.length
, (char *)mech_desc
.value
);
121 rtbl_add_column_entryv(ct
, COL_SASL
, "%.*s",
122 (int)sasl_name
.length
, (char *)sasl_name
.value
);
124 gss_release_buffer(&min_stat
, &mech_name
);
125 gss_release_buffer(&min_stat
, &mech_desc
);
126 gss_release_buffer(&min_stat
, &sasl_name
);
129 gss_release_oid_set(&min_stat
, &mechs
);
131 rtbl_format(ct
, stdout
);
138 print_mech_attr(const char *mechname
, gss_const_OID mech
, gss_OID_set set
)
140 gss_buffer_desc name
, desc
;
141 OM_uint32 major
, minor
;
147 errx(1, "rtbl_create");
149 rtbl_set_separator(ct
, " ");
150 rtbl_add_column(ct
, COL_OID
, 0);
151 rtbl_add_column(ct
, COL_DESC
, 0);
153 rtbl_add_column(ct
, COL_VALUE
, 0);
155 for (n
= 0; n
< set
->count
; n
++) {
156 major
= gss_display_mech_attr(&minor
, &set
->elements
[n
], &name
, &desc
, NULL
);
160 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
161 (int)name
.length
, (char *)name
.value
);
162 rtbl_add_column_entryv(ct
, COL_DESC
, "%.*s",
163 (int)desc
.length
, (char *)desc
.value
);
165 gss_buffer_desc value
;
167 if (gss_mo_get(mech
, &set
->elements
[n
], &value
) != 0)
171 rtbl_add_column_entryv(ct
, COL_VALUE
, "%.*s",
172 (int)value
.length
, (char *)value
.value
);
174 rtbl_add_column_entryv(ct
, COL_VALUE
, "<>");
175 gss_release_buffer(&minor
, &value
);
178 gss_release_buffer(&minor
, &name
);
179 gss_release_buffer(&minor
, &desc
);
182 printf("attributes for: %s\n", mechname
);
183 rtbl_format(ct
, stdout
);
189 attrs_for_mech(struct attrs_for_mech_options
*opt
, int argc
, char **argv
)
191 gss_OID_set mech_attr
= NULL
, known_mech_attrs
= NULL
;
192 gss_OID mech
= GSS_C_NO_OID
;
193 OM_uint32 major
, minor
;
195 if (opt
->mech_string
) {
196 mech
= gss_name_to_oid(opt
->mech_string
);
198 errx(1, "mech %s is unknown", opt
->mech_string
);
201 major
= gss_inquire_attrs_for_mech(&minor
, mech
, &mech_attr
, &known_mech_attrs
);
203 errx(1, "gss_inquire_attrs_for_mech");
206 print_mech_attr(opt
->mech_string
, mech
, mech_attr
);
210 print_mech_attr("all mechs", NULL
, known_mech_attrs
);
213 gss_release_oid_set(&minor
, &mech_attr
);
214 gss_release_oid_set(&minor
, &known_mech_attrs
);
225 help(void *opt
, int argc
, char **argv
)
227 sl_slc_help(commands
, argc
, argv
);
232 main(int argc
, char **argv
)
236 setprogname(argv
[0]);
237 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
252 help(NULL
, argc
, argv
);
256 return sl_command (commands
, argc
, argv
);