2 * Copyright (c) 2011, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
33 * This code was adapted from the MIT Kerberos Consortium's
34 * GSS example code, which was distributed under the following
37 * Copyright 2004-2006 Massachusetts Institute of Technology.
38 * All Rights Reserved.
40 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
41 * distribute this software and its documentation for any purpose and
42 * without fee is hereby granted, provided that the above copyright
43 * notice appear in all copies and that both that copyright notice and
44 * this permission notice appear in supporting documentation, and that
45 * the name of M.I.T. not be used in advertising or publicity pertaining
46 * to distribution of the software without specific, written prior
47 * permission. Furthermore if you modify this software you must label
48 * your software as modified software and not distribute it in such a
49 * fashion that it might be confused with the original M.I.T. software.
50 * M.I.T. makes no representations about the suitability of
51 * this software for any purpose. It is provided "as is" without express
52 * or implied warranty.
58 #include <sys/types.h>
64 #include <sys/socket.h>
65 #include <netinet/in.h>
68 #include <gssapi/gssapi.h>
69 #include <gssapi/gssapi_krb5.h>
73 #define kDefaultPort 2000
74 extern const char *gServiceName;
76 typedef int (*client_cb_fn)(
77 gss_name_t client_name, gss_buffer_t client_display_name,
80 int gsscon_read_token (int inSocket,
82 size_t *outTokenLength);
84 int gsscon_write_token (int inSocket,
85 const char *inTokenValue,
86 size_t inTokenLength);
88 int gsscon_read_encrypted_token (int inSocket,
89 const gss_ctx_id_t inContext,
91 size_t *outTokenLength);
93 int gsscon_write_encrypted_token (int inSocket,
94 const gss_ctx_id_t inContext,
96 size_t inTokenLength);
98 void gsscon_print_error (int inError,
99 const char *inString);
101 void gsscon_print_gss_errors (const char *inRoutineName,
102 OM_uint32 inMajorStatus,
103 OM_uint32 inMinorStatus);
105 int gsscon_connect (const char *inHost,
107 const char *inServiceName,
109 gss_ctx_id_t *outGSSContext);
111 int gsscon_passive_authenticate (int inSocket,
112 gss_ctx_id_t *outGSSContext,
113 client_cb_fn client_cb,
114 void *client_cb_data);
116 int gsscon_authorize (gss_ctx_id_t inContext,
118 int *outAuthorizationError);