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.
50 gss_print_errors (int min_stat
)
53 OM_uint32 msg_ctx
= 0;
54 gss_buffer_desc status_string
;
58 ret
= gss_display_status (&new_stat
,
64 if (!GSS_ERROR(ret
)) {
65 fprintf (stderr
, "%s\n", (char *)status_string
.value
);
66 gss_release_buffer (&new_stat
, &status_string
);
68 } while (!GSS_ERROR(ret
) && msg_ctx
!= 0);
72 gss_err(int exitval
, int status
, const char *fmt
, ...)
78 gss_print_errors (status
);
83 static int version_flag
= 0;
84 static int help_flag
= 0;
86 static struct getargs args
[] = {
87 {"version", 0, arg_flag
, &version_flag
, "print version", NULL
},
88 {"help", 0, arg_flag
, &help_flag
, NULL
, NULL
}
94 arg_printusage (args
, sizeof(args
)/sizeof(*args
),
95 NULL
, "service@host");
101 main(int argc
, char **argv
)
103 gss_buffer_desc name_buffer
;
104 OM_uint32 maj_stat
, min_stat
;
105 gss_name_t name
, MNname
, MNname2
;
110 setprogname(argv
[0]);
111 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
129 len
= asprintf(&str
, "ftp@freeze-arrow.mit.edu");
133 name_buffer
.value
= str
;
134 name_buffer
.length
= len
;
136 maj_stat
= gss_import_name(&min_stat
, &name_buffer
,
137 GSS_C_NT_HOSTBASED_SERVICE
,
139 if (maj_stat
!= GSS_S_COMPLETE
)
140 gss_err(1, min_stat
, "import name error");
143 maj_stat
= gss_canonicalize_name (&min_stat
,
147 if (maj_stat
!= GSS_S_COMPLETE
)
148 gss_err(1, min_stat
, "canonicalize name error");
150 maj_stat
= gss_export_name(&min_stat
,
153 if (maj_stat
!= GSS_S_COMPLETE
)
154 gss_err(1, min_stat
, "export name error (KRB5)");
157 * Import the exported name and compare
160 maj_stat
= gss_import_name(&min_stat
, &name_buffer
,
161 GSS_C_NT_EXPORT_NAME
,
163 if (maj_stat
!= GSS_S_COMPLETE
)
164 gss_err(1, min_stat
, "import name error (exported KRB5 name)");
167 maj_stat
= gss_compare_name(&min_stat
, MNname
, MNname2
, &equal
);
168 if (maj_stat
!= GSS_S_COMPLETE
)
169 errx(1, "gss_compare_name");
171 errx(1, "names not equal");
173 gss_release_name(&min_stat
, &MNname2
);
174 gss_release_buffer(&min_stat
, &name_buffer
);
175 gss_release_name(&min_stat
, &MNname
);
176 gss_release_name(&min_stat
, &name
);
179 * Import oid less name and compare to mech name.
180 * Dovecot SASL lib does this.
183 len
= asprintf(&str
, "lha");
187 name_buffer
.value
= str
;
188 name_buffer
.length
= len
;
190 maj_stat
= gss_import_name(&min_stat
, &name_buffer
,
193 if (maj_stat
!= GSS_S_COMPLETE
)
194 gss_err(1, min_stat
, "import (no oid) name error");
196 maj_stat
= gss_import_name(&min_stat
, &name_buffer
,
197 GSS_KRB5_NT_USER_NAME
,
199 if (maj_stat
!= GSS_S_COMPLETE
)
200 gss_err(1, min_stat
, "import (krb5 mn) name error");
204 maj_stat
= gss_compare_name(&min_stat
, name
, MNname
, &equal
);
205 if (maj_stat
!= GSS_S_COMPLETE
)
206 errx(1, "gss_compare_name");
208 errx(1, "names not equal");
210 gss_release_name(&min_stat
, &MNname
);
211 gss_release_name(&min_stat
, &name
);
214 maj_stat
= gss_canonicalize_name (&min_stat
,
216 GSS_SPNEGO_MECHANISM
,
218 if (maj_stat
!= GSS_S_COMPLETE
)
219 gss_err(1, min_stat
, "canonicalize name error");
222 maj_stat
= gss_export_name(&maj_stat
,
225 if (maj_stat
!= GSS_S_COMPLETE
)
226 gss_err(1, min_stat
, "export name error (SPNEGO)");
228 gss_release_name(&min_stat
, &MNname
);
229 gss_release_buffer(&min_stat
, &name_buffer
);