globus_i_xio_gsi.h

00001 /*
00002  * Copyright 1999-2006 University of Chicago
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef GLOBUS_I_XIO_GSI_H
00018 #define GLOBUS_I_XIO_GSI_H
00019 
00020 #include <assert.h>
00021 #include "globus_xio_driver.h"
00022 #include "globus_xio_load.h"
00023 #include "globus_common.h"
00024 #include "globus_xio_gsi.h"
00025 #include "gssapi.h"
00026 #include "globus_gss_assist.h"
00027 #include "globus_error_gssapi.h"
00028 
00029 #define GLOBUS_XIO_GSI_DRIVER_MODULE GlobusXIOMyModule(gsi)
00030 
00031 /* create/calculate a token header */
00032 
00033 #define GlobusLXIOGSICreateHeader(__iovec, __length)              \
00034     {                                                             \
00035         *(((unsigned char *) (__iovec).iov_base)) =               \
00036             (unsigned char) (((__length) >> 24) & 0xff);          \
00037         *(((unsigned char *) (__iovec).iov_base)+1) =             \
00038             (unsigned char) (((__length) >> 16) & 0xff);          \
00039         *(((unsigned char *) (__iovec).iov_base)+2) =             \
00040             (unsigned char) (((__length) >>  8) & 0xff);          \
00041         *(((unsigned char *) (__iovec).iov_base)+3) =             \
00042             (unsigned char) (((__length)      ) & 0xff);          \
00043     }
00044 
00045 /* get the token length from a wrapped token */
00046 
00047 #define GlobusLXIOGSIGetTokenLength(__iovec, __length)            \
00048     {                                                             \
00049         globus_byte_t *                 c;                        \
00050         c = (__iovec).iov_base;                                   \
00051         (__length)  = ((globus_size_t) (*((c)++))) << 24;         \
00052         (__length) |= ((globus_size_t) (*((c)++))) << 16;         \
00053         (__length) |= ((globus_size_t) (*((c)++))) << 8;          \
00054         (__length) |= ((globus_size_t) (*((c)++)));               \
00055     }
00056 
00057 
00058 /* macro for wrapping gssapi errors */
00059 
00060 #define GlobusXIOErrorWrapGSSFailed(failed_func, major_status, minor_status) \
00061     globus_error_put(                                                        \
00062         globus_error_wrap_gssapi_error(                                      \
00063             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00064             (major_status),                                                  \
00065             (minor_status),                                                  \
00066             GLOBUS_XIO_GSI_ERROR_WRAP_GSSAPI,                                \
00067             __FILE__,                                                        \
00068             _xio_name,                                                       \
00069             __LINE__,                                                        \
00070             _XIOSL("%s failed."),                                                    \
00071             (failed_func)))
00072 
00073 
00074 #define GlobusXioGSIErrorBadProtectionLevel()                                \
00075     globus_error_put(                                                        \
00076         globus_error_construct_error(                                        \
00077             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00078             GLOBUS_NULL,                                                     \
00079             GLOBUS_XIO_GSI_ERROR_INVALID_PROTECTION_LEVEL,                   \
00080             __FILE__,                                                        \
00081             _xio_name,                                                       \
00082             __LINE__,                                                        \
00083             _XIOSL("Peer specified lower protection level")))
00084 
00085 #define GlobusXioGSIErrorTokenTooBig()                                       \
00086     globus_error_put(                                                        \
00087         globus_error_construct_error(                                        \
00088             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00089             GLOBUS_NULL,                                                     \
00090             GLOBUS_XIO_GSI_ERROR_TOKEN_TOO_BIG,                              \
00091             __FILE__,                                                        \
00092             _xio_name,                                                       \
00093             __LINE__,                                                        \
00094             _XIOSL("Token size exceeds limit. Usually happens when someone tries to establish a insecure connection with a secure endpoint, e.g. when someone sends plain HTTP to a HTTPS endpoint without first establishing a SSL session.")))
00095 
00096 #define GlobusXioGSIErrorEmptyTargetName()                                   \
00097     globus_error_put(                                                        \
00098         globus_error_construct_error(                                        \
00099             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00100             GLOBUS_NULL,                                                     \
00101             GLOBUS_XIO_GSI_ERROR_EMPTY_TARGET_NAME,                          \
00102             __FILE__,                                                        \
00103             _xio_name,                                                       \
00104             __LINE__,                                                        \
00105             _XIOSL("Identity authorization requested, but no target name set")))
00106 
00107 #define GlobusXioGSIErrorEmptyHostName()                                     \
00108     globus_error_put(                                                        \
00109         globus_error_construct_error(                                        \
00110             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00111             GLOBUS_NULL,                                                     \
00112             GLOBUS_XIO_GSI_ERROR_EMPTY_HOST_NAME,                            \
00113             __FILE__,                                                        \
00114             _xio_name,                                                       \
00115             __LINE__,                                                        \
00116             _XIOSL("Host authorization requested, but no host name set")))
00117 
00118 #define GlobusXioGSIAuthorizationFailed(_peer_name, _expected_name)          \
00119     globus_error_put(                                                        \
00120         globus_error_construct_error(                                        \
00121             GLOBUS_XIO_GSI_DRIVER_MODULE,                                    \
00122             GLOBUS_NULL,                                                     \
00123             GLOBUS_XIO_GSI_AUTHORIZATION_FAILED,                             \
00124             __FILE__,                                                        \
00125             _xio_name,                                                       \
00126             __LINE__,                                                        \
00127             _XIOSL("The peer authenticated as %s. Expected the peer "               \
00128             "to authenticate as %s"), (_peer_name), (_expected_name)))
00129 
00130 
00131 /* XIO debug stuff */
00132 
00133 GlobusDebugDeclare(GLOBUS_XIO_GSI);
00134 
00135 #define GLOBUS_XIO_GSI_DEBUG_TRACE 4
00136 #define GLOBUS_XIO_GSI_DEBUG_INTERNAL_TRACE 8
00137 
00138 #define GlobusXIOGSIDebugPrintf(level, message)                             \
00139     GlobusDebugPrintf(GLOBUS_XIO_GSI, level, message)
00140 
00141 #define GlobusXIOGSIDebugEnter()                                            \
00142     GlobusXIOGSIDebugPrintf(                                                \
00143         GLOBUS_XIO_GSI_DEBUG_TRACE,                                         \
00144         (_XIOSL("[%s] Entering\n"), _xio_name))
00145 
00146 #define GlobusXIOGSIDebugExit()                                             \
00147     GlobusXIOGSIDebugPrintf(                                                \
00148         GLOBUS_XIO_GSI_DEBUG_TRACE,                                         \
00149         (_XIOSL("[%s] Exiting\n"), _xio_name))
00150 
00151 #define GlobusXIOGSIDebugExitWithError()                                    \
00152     GlobusXIOGSIDebugPrintf(                                                \
00153         GLOBUS_XIO_GSI_DEBUG_TRACE,                                         \
00154         (_XIOSL("[%s] Exiting with error\n"), _xio_name))
00155 
00156 #define GlobusXIOGSIDebugInternalEnter()                                    \
00157     GlobusXIOGSIDebugPrintf(                                                \
00158         GLOBUS_XIO_GSI_DEBUG_INTERNAL_TRACE,                                \
00159         (_XIOSL("[%s] I Entering\n"), _xio_name))
00160 
00161 #define GlobusXIOGSIDebugInternalExit()                                     \
00162     GlobusXIOGSIDebugPrintf(                                                \
00163         GLOBUS_XIO_GSI_DEBUG_INTERNAL_TRACE,                                \
00164         (_XIOSL("[%s] I Exiting\n"), _xio_name))
00165 
00166 #define GlobusXIOGSIDebugInternalExitWithError()                            \
00167     GlobusXIOGSIDebugPrintf(                                                \
00168         GLOBUS_XIO_GSI_DEBUG_INTERNAL_TRACE,                                \
00169         (_XIOSL("[%s] I Exiting with error\n"), _xio_name))
00170 
00171 /*
00172  *  attribute structure
00173  */
00174 typedef struct
00175 {
00176     gss_cred_id_t                       credential;
00177     OM_uint32                           req_flags;
00178     OM_uint32                           time_req;
00179     gss_OID                             mech_type;
00180     gss_channel_bindings_t              channel_bindings;
00181     globus_bool_t                       wrap_tokens;
00182     globus_size_t                       buffer_size;
00183     globus_xio_gsi_protection_level_t   prot_level;
00184     gss_name_t                          target_name;
00185     globus_bool_t                       init;
00186     globus_xio_gsi_authorization_mode_t authz_mode;
00187 } globus_l_attr_t;
00188 
00189 /*
00190  * driver handle structure
00191  */
00192 
00193 typedef struct
00194 {
00195     globus_l_attr_t *                   attr;
00196     OM_uint32                           ret_flags;
00197     OM_uint32                           time_rec;
00198     OM_uint32                           max_wrap_size;
00199     gss_ctx_id_t                        context;
00200     gss_cred_id_t                       delegated_cred;
00201     gss_cred_id_t                       credential;
00202     gss_OID                             mech_used;
00203     gss_name_t                          peer_name;
00204     gss_name_t                          local_name;
00205     size_t                              write_iovec_count;
00206     globus_xio_iovec_t *                write_iovec;
00207     globus_bool_t                       frame_writes;
00208     size_t                              write_header_count;
00209     unsigned char *                     write_headers;
00210     globus_size_t                       bytes_written;
00211     globus_xio_iovec_t                  read_iovec[2];
00212     unsigned char                       header[4];
00213     unsigned char *                     read_buffer;
00214     globus_size_t                       bytes_read;
00215     globus_xio_iovec_t *                user_iovec;
00216     size_t                              user_iovec_count;
00217     size_t                              user_iovec_index;
00218     size_t                              user_iovec_offset;
00219     unsigned char *                     unwrapped_buffer;
00220     globus_size_t                       unwrapped_buffer_length;
00221     globus_size_t                       unwrapped_buffer_offset;
00222     globus_size_t                       bytes_returned;
00223     globus_bool_t                       done;
00224     globus_object_t *                   result_obj;
00225     globus_bool_t                       eof;
00226     int                                 connection_id;
00227     globus_xio_driver_handle_t          xio_driver_handle;
00228     char *                              host_name;
00229 } globus_l_handle_t;
00230 
00231 /*
00232  * Structure used for passing information needed for the init/accept delegation
00233  * operations 
00234  */
00235 
00236 typedef struct
00237 {
00238     globus_l_handle_t *                 xio_handle;
00239     void *                              user_arg;
00240     globus_xio_gsi_delegation_init_callback_t
00241                                         init_callback;
00242     globus_xio_gsi_delegation_accept_callback_t
00243                                         accept_callback;
00244     gss_cred_id_t                       cred;
00245     gss_OID_set                         restriction_oids;
00246     gss_buffer_set_t                    restriction_buffers;
00247     OM_uint32                           time_req;
00248     OM_uint32                           time_rec;
00249     globus_xio_iovec_t                  iovec[2];
00250     unsigned char                       header[4];
00251     globus_bool_t                       done;
00252     globus_object_t *                   result_obj;
00253     globus_bool_t                       reading_header;
00254 } globus_l_delegation_handle_t;
00255 
00256 typedef struct
00257 {
00258     globus_bool_t                       done;
00259     globus_result_t                     result;
00260     globus_mutex_t                      mutex;
00261     globus_cond_t                       cond;
00262     OM_uint32 *                         time_rec;
00263     gss_cred_id_t *                     cred;
00264 } globus_l_xio_gsi_delegation_arg_t;
00265 
00266 #endif
00267 

Generated on 11 May 2016 for globus_xio_gsi_driver by  doxygen 1.4.7