Spelling.
[heimdal.git] / lib / gssapi / gss.c
blob3a354ae068166e6431e3fed69240c7b5448d3002
1 /*
2 * Copyright (c) 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <stdio.h>
39 #include <gssapi.h>
40 #include <err.h>
41 #include <roken.h>
42 #include <getarg.h>
43 #include <rtbl.h>
44 #include <gss-commands.h>
45 #include <krb5.h>
47 RCSID("$Id$");
49 static int version_flag = 0;
50 static int help_flag = 0;
52 static struct getargs args[] = {
53 {"version", 0, arg_flag, &version_flag, "print version", NULL },
54 {"help", 0, arg_flag, &help_flag, NULL, NULL }
57 static void
58 usage (int ret)
60 arg_printusage (args, sizeof(args)/sizeof(*args),
61 NULL, "service@host");
62 exit (ret);
65 #define COL_OID "OID"
66 #define COL_NAME "Name"
68 int
69 supported_mechanisms(void *argptr, int argc, char **argv)
71 OM_uint32 maj_stat, min_stat;
72 gss_OID_set mechs;
73 rtbl_t ct;
74 size_t i;
76 maj_stat = gss_indicate_mechs(&min_stat, &mechs);
77 if (maj_stat != GSS_S_COMPLETE)
78 errx(1, "gss_indicate_mechs failed");
80 printf("Supported mechanisms:\n");
82 ct = rtbl_create();
83 if (ct == NULL)
84 errx(1, "rtbl_create");
86 rtbl_set_separator(ct, " ");
87 rtbl_add_column(ct, COL_OID, 0);
88 rtbl_add_column(ct, COL_NAME, 0);
90 for (i = 0; i < mechs->count; i++) {
91 gss_buffer_desc name;
93 maj_stat = gss_oid_to_str(&min_stat, &mechs->elements[i], &name);
94 if (maj_stat != GSS_S_COMPLETE)
95 errx(1, "gss_oid_to_str failed");
97 rtbl_add_column_entryv(ct, COL_OID, "%.*s",
98 (int)name.length, (char *)name.value);
99 gss_release_buffer(&min_stat, &name);
101 if (gss_oid_equal(&mechs->elements[i], GSS_KRB5_MECHANISM))
102 rtbl_add_column_entry(ct, COL_NAME, "Kerberos 5");
103 else if (gss_oid_equal(&mechs->elements[i], GSS_SPNEGO_MECHANISM))
104 rtbl_add_column_entry(ct, COL_NAME, "SPNEGO");
105 else if (gss_oid_equal(&mechs->elements[i], GSS_NTLM_MECHANISM))
106 rtbl_add_column_entry(ct, COL_NAME, "NTLM");
108 gss_release_oid_set(&min_stat, &mechs);
110 rtbl_format(ct, stdout);
111 rtbl_destroy(ct);
113 return 0;
116 #if 0
121 #define DOVEDOT_MAJOR_VERSION 1
122 #define DOVEDOT_MINOR_VERSION 0
125 S: MECH mech mech-parameters
126 S: MECH mech mech-parameters
127 S: VERSION major minor
128 S: CPID pid
129 S: CUID pid
130 S: ...
131 S: DONE
132 C: VERSION major minor
133 C: CPID pid
135 C: AUTH id method service= resp=
136 C: CONT id message
138 S: OK id user=
139 S: FAIL id reason=
140 S: CONTINUE id message
144 dovecot_server(void *argptr, int argc, char **argv)
146 krb5_storage *sp;
147 int fd = 0;
149 sp = krb5_storage_from_fd(fd);
150 if (sp == NULL)
151 errx(1, "krb5_storage_from_fd");
153 krb5_store_stringnl(sp, "MECH\tGSSAPI");
154 krb5_store_stringnl(sp, "VERSION\t1\t0");
155 krb5_store_stringnl(sp, "DONE");
157 while (1) {
158 char *cmd;
159 if (krb5_ret_stringnl(sp, &cmd) != 0)
160 break;
161 printf("cmd: %s\n", cmd);
162 free(cmd);
164 return 0;
166 #endif
173 help(void *opt, int argc, char **argv)
175 sl_slc_help(commands, argc, argv);
176 return 0;
180 main(int argc, char **argv)
182 int optidx = 0;
184 setprogname(argv[0]);
185 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
186 usage(1);
188 if (help_flag)
189 usage (0);
191 if(version_flag){
192 print_version(NULL);
193 exit(0);
196 argc -= optidx;
197 argv += optidx;
199 if (argc == 0) {
200 help(NULL, argc, argv);
201 return 1;
204 return sl_command (commands, argc, argv);