Windows: Make application manifest available everywhere
[heimdal.git] / lib / gssapi / gss.c
blob92754581f43d7dd2261f434beb5247cacf9dfca3
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 <gssapi_krb5.h>
41 #include <gssapi_spnego.h>
42 #include <gssapi_ntlm.h>
43 #include <err.h>
44 #include <roken.h>
45 #include <getarg.h>
46 #include <rtbl.h>
47 #include <gss-commands.h>
48 #include <krb5.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 }
58 static void
59 usage (int ret)
61 arg_printusage (args, sizeof(args)/sizeof(*args),
62 NULL, "service@host");
63 exit (ret);
66 #define COL_OID "OID"
67 #define COL_NAME "Name"
69 int
70 supported_mechanisms(void *argptr, int argc, char **argv)
72 OM_uint32 maj_stat, min_stat;
73 gss_OID_set mechs;
74 rtbl_t ct;
75 size_t i;
77 maj_stat = gss_indicate_mechs(&min_stat, &mechs);
78 if (maj_stat != GSS_S_COMPLETE)
79 errx(1, "gss_indicate_mechs failed");
81 printf("Supported mechanisms:\n");
83 ct = rtbl_create();
84 if (ct == NULL)
85 errx(1, "rtbl_create");
87 rtbl_set_separator(ct, " ");
88 rtbl_add_column(ct, COL_OID, 0);
89 rtbl_add_column(ct, COL_NAME, 0);
91 for (i = 0; i < mechs->count; i++) {
92 gss_buffer_desc name;
94 maj_stat = gss_oid_to_str(&min_stat, &mechs->elements[i], &name);
95 if (maj_stat != GSS_S_COMPLETE)
96 errx(1, "gss_oid_to_str failed");
98 rtbl_add_column_entryv(ct, COL_OID, "%.*s",
99 (int)name.length, (char *)name.value);
100 gss_release_buffer(&min_stat, &name);
102 if (gss_oid_equal(&mechs->elements[i], GSS_KRB5_MECHANISM))
103 rtbl_add_column_entry(ct, COL_NAME, "Kerberos 5");
104 else if (gss_oid_equal(&mechs->elements[i], GSS_SPNEGO_MECHANISM))
105 rtbl_add_column_entry(ct, COL_NAME, "SPNEGO");
106 else if (gss_oid_equal(&mechs->elements[i], GSS_NTLM_MECHANISM))
107 rtbl_add_column_entry(ct, COL_NAME, "NTLM");
109 gss_release_oid_set(&min_stat, &mechs);
111 rtbl_format(ct, stdout);
112 rtbl_destroy(ct);
114 return 0;
117 #if 0
122 #define DOVEDOT_MAJOR_VERSION 1
123 #define DOVEDOT_MINOR_VERSION 0
126 S: MECH mech mech-parameters
127 S: MECH mech mech-parameters
128 S: VERSION major minor
129 S: CPID pid
130 S: CUID pid
131 S: ...
132 S: DONE
133 C: VERSION major minor
134 C: CPID pid
136 C: AUTH id method service= resp=
137 C: CONT id message
139 S: OK id user=
140 S: FAIL id reason=
141 S: CONTINUE id message
145 dovecot_server(void *argptr, int argc, char **argv)
147 krb5_storage *sp;
148 int fd = 0;
150 sp = krb5_storage_from_fd(fd);
151 if (sp == NULL)
152 errx(1, "krb5_storage_from_fd");
154 krb5_store_stringnl(sp, "MECH\tGSSAPI");
155 krb5_store_stringnl(sp, "VERSION\t1\t0");
156 krb5_store_stringnl(sp, "DONE");
158 while (1) {
159 char *cmd;
160 if (krb5_ret_stringnl(sp, &cmd) != 0)
161 break;
162 printf("cmd: %s\n", cmd);
163 free(cmd);
165 return 0;
167 #endif
174 help(void *opt, int argc, char **argv)
176 sl_slc_help(commands, argc, argv);
177 return 0;
181 main(int argc, char **argv)
183 int optidx = 0;
185 setprogname(argv[0]);
186 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
187 usage(1);
189 if (help_flag)
190 usage (0);
192 if(version_flag){
193 print_version(NULL);
194 exit(0);
197 argc -= optidx;
198 argv += optidx;
200 if (argc == 0) {
201 help(NULL, argc, argv);
202 return 1;
205 return sl_command (commands, argc, argv);