Use json_is_true() in place of json_boolean_value() for compatibility
[trust_router.git] / include / gsscon.h
1 /*
2  * Copyright (c) 2011, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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.
15  *
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.
19  *
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.
32  *
33  * This code was adapted from the MIT Kerberos Consortium's
34  * GSS example code, which was distributed under the following
35  * license:
36  *
37  * Copyright 2004-2006 Massachusetts Institute of Technology.
38  * All Rights Reserved.
39  *
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.
53  */
54
55 #ifndef GSSCON_H
56 #define GSSCON_H
57
58 #include <sys/types.h>
59 #include <sys/uio.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <unistd.h>
64 #include <sys/socket.h>
65 #include <netinet/in.h>
66 #include <netdb.h>
67
68 #include <gssapi/gssapi.h>
69 #include <gssapi/gssapi_krb5.h>
70 #include <krb5.h>
71 #include <errno.h>
72
73 #define kDefaultPort 2000
74 extern const char *gServiceName;
75
76 typedef int (*client_cb_fn)(
77                             gss_name_t client_name, gss_buffer_t client_display_name,
78                             void *);
79
80 int gsscon_read_token (int      inSocket, 
81                char   **outTokenValue, 
82                size_t  *outTokenLength);
83
84 int gsscon_write_token (int         inSocket, 
85                         const char *inTokenValue, 
86                         size_t      inTokenLength);
87
88 int gsscon_read_encrypted_token (int                  inSocket, 
89                                  const gss_ctx_id_t   inContext, 
90                                  char               **outTokenValue, 
91                                  size_t              *outTokenLength);
92
93 int gsscon_write_encrypted_token (int                 inSocket, 
94                                   const gss_ctx_id_t  inContext, 
95                                   const char         *inToken, 
96                                   size_t              inTokenLength);
97
98 void gsscon_print_error (int         inError, 
99                          const char *inString);
100
101 void gsscon_print_gss_errors (const char *inRoutineName, 
102                               OM_uint32   inMajorStatus, 
103                               OM_uint32   inMinorStatus);
104
105 int gsscon_connect (const char *inHost, 
106                     unsigned int inPort, 
107                     const char *inServiceName,
108                     int *outFD,
109                     gss_ctx_id_t *outGSSContext);
110
111 int gsscon_passive_authenticate (int           inSocket, 
112                                  gss_buffer_desc inNameBuffer,
113                                  gss_ctx_id_t *outGSSContext,
114                                  client_cb_fn client_cb,
115                                  void *client_cb_data);
116
117 int gsscon_authorize (gss_ctx_id_t  inContext, 
118                       int          *outAuthorized, 
119                       int          *outAuthorizationError);
120
121 #endif