2 * Copyright (c) 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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"
70 supported_mechanisms(void *argptr
, int argc
, char **argv
)
72 OM_uint32 maj_stat
, min_stat
;
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");
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
++) {
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
);
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
133 C: VERSION major minor
136 C: AUTH id method service= resp=
141 S: CONTINUE id message
145 dovecot_server(void *argptr
, int argc
, char **argv
)
150 sp
= krb5_storage_from_fd(fd
);
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");
160 if (krb5_ret_stringnl(sp
, &cmd
) != 0)
162 printf("cmd: %s\n", cmd
);
174 help(void *opt
, int argc
, char **argv
)
176 sl_slc_help(commands
, argc
, argv
);
181 main(int argc
, char **argv
)
185 setprogname(argv
[0]);
186 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
201 help(NULL
, argc
, argv
);
205 return sl_command (commands
, argc
, argv
);