2 * Copyright (c) 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of KTH nor the names of its contributors may be
20 * used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <gssapi_krb5.h>
42 #include <gssapi_spnego.h>
43 #include <gssapi_ntlm.h>
47 #include <gss-commands.h>
50 static int version_flag
= 0;
51 static int help_flag
= 0;
53 static struct getargs args
[] = {
54 {"version", 0, arg_flag
, &version_flag
, "print version", NULL
},
55 {"help", 0, arg_flag
, &help_flag
, NULL
, NULL
}
61 arg_printusage (args
, sizeof(args
)/sizeof(*args
),
62 NULL
, "service@host");
67 #define COL_NAME "Name"
68 #define COL_DESC "Description"
69 #define COL_VALUE "Value"
70 #define COL_MECH "Mech"
71 #define COL_EXPIRE "Expire"
72 #define COL_SASL "SASL"
75 mechanisms(void *argptr
, int argc
, char **argv
)
77 OM_uint32 maj_stat
, min_stat
;
82 maj_stat
= gss_indicate_mechs(&min_stat
, &mechs
);
83 if (maj_stat
!= GSS_S_COMPLETE
)
84 errx(1, "gss_indicate_mechs failed");
86 printf("Supported mechanisms:\n");
90 errx(1, "rtbl_create");
92 rtbl_set_separator(ct
, " ");
93 rtbl_add_column(ct
, COL_OID
, 0);
94 rtbl_add_column(ct
, COL_NAME
, 0);
95 rtbl_add_column(ct
, COL_DESC
, 0);
96 rtbl_add_column(ct
, COL_SASL
, 0);
98 for (i
= 0; i
< mechs
->count
; i
++) {
99 gss_buffer_desc str
, sasl_name
, mech_name
, mech_desc
;
101 maj_stat
= gss_oid_to_str(&min_stat
, &mechs
->elements
[i
], &str
);
102 if (maj_stat
!= GSS_S_COMPLETE
)
103 errx(1, "gss_oid_to_str failed");
105 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
106 (int)str
.length
, (char *)str
.value
);
107 gss_release_buffer(&min_stat
, &str
);
109 (void)gss_inquire_saslname_for_mech(&min_stat
,
115 rtbl_add_column_entryv(ct
, COL_NAME
, "%.*s",
116 (int)mech_name
.length
, (char *)mech_name
.value
);
117 rtbl_add_column_entryv(ct
, COL_DESC
, "%.*s",
118 (int)mech_desc
.length
, (char *)mech_desc
.value
);
119 rtbl_add_column_entryv(ct
, COL_SASL
, "%.*s",
120 (int)sasl_name
.length
, (char *)sasl_name
.value
);
122 gss_release_buffer(&min_stat
, &mech_name
);
123 gss_release_buffer(&min_stat
, &mech_desc
);
124 gss_release_buffer(&min_stat
, &sasl_name
);
127 gss_release_oid_set(&min_stat
, &mechs
);
129 rtbl_format(ct
, stdout
);
136 print_mech_attr(const char *mechname
, gss_const_OID mech
, gss_OID_set set
)
138 gss_buffer_desc name
, desc
;
139 OM_uint32 major
, minor
;
145 errx(1, "rtbl_create");
147 rtbl_set_separator(ct
, " ");
148 rtbl_add_column(ct
, COL_OID
, 0);
149 rtbl_add_column(ct
, COL_DESC
, 0);
151 rtbl_add_column(ct
, COL_VALUE
, 0);
153 for (n
= 0; n
< set
->count
; n
++) {
154 major
= gss_display_mech_attr(&minor
, &set
->elements
[n
], &name
, &desc
, NULL
);
158 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
159 (int)name
.length
, (char *)name
.value
);
160 rtbl_add_column_entryv(ct
, COL_DESC
, "%.*s",
161 (int)desc
.length
, (char *)desc
.value
);
163 gss_buffer_desc value
;
165 if (gss_mo_get(mech
, &set
->elements
[n
], &value
) != 0)
169 rtbl_add_column_entryv(ct
, COL_VALUE
, "%.*s",
170 (int)value
.length
, (char *)value
.value
);
172 rtbl_add_column_entryv(ct
, COL_VALUE
, "<>");
173 gss_release_buffer(&minor
, &value
);
176 gss_release_buffer(&minor
, &name
);
177 gss_release_buffer(&minor
, &desc
);
180 printf("attributes for: %s\n", mechname
);
181 rtbl_format(ct
, stdout
);
187 attributes(struct attributes_options
*opt
, int argc
, char **argv
)
189 gss_OID_set mech_attr
= NULL
, known_mech_attrs
= NULL
;
190 gss_OID mech
= GSS_C_NO_OID
;
191 OM_uint32 major
, minor
;
193 if (opt
->mech_string
) {
194 mech
= gss_name_to_oid(opt
->mech_string
);
196 errx(1, "mech %s is unknown", opt
->mech_string
);
199 major
= gss_inquire_attrs_for_mech(&minor
, mech
, &mech_attr
, &known_mech_attrs
);
201 errx(1, "gss_inquire_attrs_for_mech");
204 print_mech_attr(opt
->mech_string
, mech
, mech_attr
);
208 print_mech_attr("all mechs", NULL
, known_mech_attrs
);
211 gss_release_oid_set(&minor
, &mech_attr
);
212 gss_release_oid_set(&minor
, &known_mech_attrs
);
223 help(void *opt
, int argc
, char **argv
)
225 sl_slc_help(commands
, argc
, argv
);
230 main(int argc
, char **argv
)
232 int exit_status
= 0, ret
, optidx
= 0;
234 setprogname(argv
[0]);
236 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
251 ret
= sl_command(commands
, argc
, argv
);
253 sl_did_you_mean(commands
, argv
[0]);
259 sl_slc_help(commands
, argc
, argv
);