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.
40 #include <gssapi_krb5.h>
41 #include <gssapi_spnego.h>
42 #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"
74 supported_mechanisms(void *argptr
, int argc
, char **argv
)
76 OM_uint32 maj_stat
, min_stat
;
81 maj_stat
= gss_indicate_mechs(&min_stat
, &mechs
);
82 if (maj_stat
!= GSS_S_COMPLETE
)
83 errx(1, "gss_indicate_mechs failed");
85 printf("Supported mechanisms:\n");
89 errx(1, "rtbl_create");
91 rtbl_set_separator(ct
, " ");
92 rtbl_add_column(ct
, COL_OID
, 0);
93 rtbl_add_column(ct
, COL_NAME
, 0);
95 for (i
= 0; i
< mechs
->count
; i
++) {
97 const char *name
= NULL
;
99 maj_stat
= gss_oid_to_str(&min_stat
, &mechs
->elements
[i
], &str
);
100 if (maj_stat
!= GSS_S_COMPLETE
)
101 errx(1, "gss_oid_to_str failed");
103 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
104 (int)str
.length
, (char *)str
.value
);
105 gss_release_buffer(&min_stat
, &str
);
107 name
= gss_oid_to_name(&mechs
->elements
[i
]);
109 rtbl_add_column_entry(ct
, COL_NAME
, name
);
111 gss_release_oid_set(&min_stat
, &mechs
);
113 rtbl_format(ct
, stdout
);
120 print_mech_attr(const char *mechname
, gss_const_OID mech
, gss_OID_set set
)
122 gss_buffer_desc name
, desc
;
123 OM_uint32 major
, minor
;
129 errx(1, "rtbl_create");
131 rtbl_set_separator(ct
, " ");
132 rtbl_add_column(ct
, COL_OID
, 0);
133 rtbl_add_column(ct
, COL_DESC
, 0);
135 rtbl_add_column(ct
, COL_VALUE
, 0);
137 for (n
= 0; n
< set
->count
; n
++) {
138 major
= gss_display_mech_attr(&minor
, &set
->elements
[n
], &name
, &desc
, NULL
);
142 rtbl_add_column_entryv(ct
, COL_OID
, "%.*s",
143 (int)name
.length
, (char *)name
.value
);
144 rtbl_add_column_entryv(ct
, COL_DESC
, "%.*s",
145 (int)desc
.length
, (char *)desc
.value
);
147 gss_buffer_desc value
;
149 if (gss_mo_get(mech
, &set
->elements
[n
], &value
) != 0)
153 rtbl_add_column_entryv(ct
, COL_VALUE
, "%.*s",
154 (int)value
.length
, (char *)value
.value
);
156 rtbl_add_column_entryv(ct
, COL_VALUE
, "<>");
157 gss_release_buffer(&minor
, &value
);
160 gss_release_buffer(&minor
, &name
);
161 gss_release_buffer(&minor
, &desc
);
164 printf("attributes for: %s\n", mechname
);
165 rtbl_format(ct
, stdout
);
171 attrs_for_mech(struct attrs_for_mech_options
*opt
, int argc
, char **argv
)
173 gss_OID_set mech_attr
= NULL
, known_mech_attrs
= NULL
;
174 gss_OID mech
= GSS_C_NO_OID
;
175 OM_uint32 major
, minor
;
177 if (opt
->mech_string
) {
178 mech
= gss_name_to_oid(opt
->mech_string
);
180 errx(1, "mech %s is unknown", opt
->mech_string
);
183 major
= gss_inquire_attrs_for_mech(&minor
, mech
, &mech_attr
, &known_mech_attrs
);
185 errx(1, "gss_inquire_attrs_for_mech");
188 print_mech_attr(opt
->mech_string
, mech
, mech_attr
);
192 print_mech_attr("all mechs", NULL
, known_mech_attrs
);
195 gss_release_oid_set(&minor
, &mech_attr
);
196 gss_release_oid_set(&minor
, &known_mech_attrs
);
207 help(void *opt
, int argc
, char **argv
)
209 sl_slc_help(commands
, argc
, argv
);
214 main(int argc
, char **argv
)
218 setprogname(argv
[0]);
219 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
234 help(NULL
, argc
, argv
);
238 return sl_command (commands
, argc
, argv
);