| 1 | /* |
| 2 | * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Oracle designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Oracle in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
| 24 | */ |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include "NativeFunc.h" |
| 29 | |
| 30 | /* standard GSS method names (ordering is from mapfile) */ |
| 31 | static const char RELEASE_NAME[] = "gss_release_name" ; |
| 32 | static const char IMPORT_NAME[] = "gss_import_name" ; |
| 33 | static const char COMPARE_NAME[] = "gss_compare_name" ; |
| 34 | static const char CANONICALIZE_NAME[] = "gss_canonicalize_name" ; |
| 35 | static const char EXPORT_NAME[] = "gss_export_name" ; |
| 36 | static const char DISPLAY_NAME[] = "gss_display_name" ; |
| 37 | static const char ACQUIRE_CRED[] = "gss_acquire_cred" ; |
| 38 | static const char RELEASE_CRED[] = "gss_release_cred" ; |
| 39 | static const char INQUIRE_CRED[] = "gss_inquire_cred" ; |
| 40 | static const char IMPORT_SEC_CONTEXT[] = "gss_import_sec_context" ; |
| 41 | static const char INIT_SEC_CONTEXT[] = "gss_init_sec_context" ; |
| 42 | static const char ACCEPT_SEC_CONTEXT[] = "gss_accept_sec_context" ; |
| 43 | static const char INQUIRE_CONTEXT[] = "gss_inquire_context" ; |
| 44 | static const char DELETE_SEC_CONTEXT[] = "gss_delete_sec_context" ; |
| 45 | static const char CONTEXT_TIME[] = "gss_context_time" ; |
| 46 | static const char WRAP_SIZE_LIMIT[] = "gss_wrap_size_limit" ; |
| 47 | static const char EXPORT_SEC_CONTEXT[] = "gss_export_sec_context" ; |
| 48 | static const char GET_MIC[] = "gss_get_mic" ; |
| 49 | static const char VERIFY_MIC[] = "gss_verify_mic" ; |
| 50 | static const char WRAP[] = "gss_wrap" ; |
| 51 | static const char UNWRAP[] = "gss_unwrap" ; |
| 52 | static const char INDICATE_MECHS[] = "gss_indicate_mechs" ; |
| 53 | static const char INQUIRE_NAMES_FOR_MECH[] = "gss_inquire_names_for_mech" ; |
| 54 | |
| 55 | /* additional GSS methods not public thru mapfile */ |
| 56 | |
| 57 | static const char ADD_OID_SET_MEMBER[] = "gss_add_oid_set_member" ; |
| 58 | static const char DISPLAY_STATUS[] = "gss_display_status" ; |
| 59 | static const char CREATE_EMPTY_OID_SET[] = "gss_create_empty_oid_set" ; |
| 60 | static const char RELEASE_OID_SET[] = "gss_release_oid_set" ; |
| 61 | static const char RELEASE_BUFFER[] = "gss_release_buffer" ; |
| 62 | |
| 63 | /** |
| 64 | * Initialize native GSS function pointers |
| 65 | */ |
| 66 | int loadNative(const char *libName) { |
| 67 | |
| 68 | void *gssLib; |
| 69 | int failed; |
| 70 | OM_uint32 minor, major; |
| 71 | |
| 72 | ftab = NULL; |
| 73 | failed = FALSE; |
| 74 | |
| 75 | gssLib = GETLIB(libName); |
| 76 | if (gssLib == NULL) { |
| 77 | failed = TRUE; |
| 78 | goto out; |
| 79 | } |
| 80 | |
| 81 | /* global function table instance */ |
| 82 | ftab = (GSS_FUNCTION_TABLE_PTR)malloc(sizeof(GSS_FUNCTION_TABLE)); |
| 83 | if (ftab == NULL) { |
| 84 | failed = TRUE; |
| 85 | goto out; |
| 86 | } |
| 87 | |
| 88 | ftab->releaseName = (RELEASE_NAME_FN_PTR)GETFUNC(gssLib, RELEASE_NAME); |
| 89 | if (ftab->releaseName == NULL) { |
| 90 | failed = TRUE; |
| 91 | goto out; |
| 92 | } |
| 93 | |
| 94 | ftab->importName = (IMPORT_NAME_FN_PTR)GETFUNC(gssLib, IMPORT_NAME); |
| 95 | if (ftab->importName == NULL) { |
| 96 | failed = TRUE; |
| 97 | goto out; |
| 98 | } |
| 99 | |
| 100 | ftab->compareName = (COMPARE_NAME_FN_PTR)GETFUNC(gssLib, COMPARE_NAME); |
| 101 | if (ftab->compareName == NULL) { |
| 102 | failed = TRUE; |
| 103 | goto out; |
| 104 | } |
| 105 | |
| 106 | ftab->canonicalizeName = (CANONICALIZE_NAME_FN_PTR) |
| 107 | GETFUNC(gssLib, CANONICALIZE_NAME); |
| 108 | if (ftab->canonicalizeName == NULL) { |
| 109 | failed = TRUE; |
| 110 | goto out; |
| 111 | } |
| 112 | |
| 113 | ftab->exportName = (EXPORT_NAME_FN_PTR)GETFUNC(gssLib, EXPORT_NAME); |
| 114 | if (ftab->exportName == NULL) { |
| 115 | failed = TRUE; |
| 116 | goto out; |
| 117 | } |
| 118 | |
| 119 | ftab->displayName = (DISPLAY_NAME_FN_PTR)GETFUNC(gssLib, DISPLAY_NAME); |
| 120 | if (ftab->displayName == NULL) { |
| 121 | failed = TRUE; |
| 122 | goto out; |
| 123 | } |
| 124 | |
| 125 | ftab->acquireCred = (ACQUIRE_CRED_FN_PTR)GETFUNC(gssLib, ACQUIRE_CRED); |
| 126 | if (ftab->acquireCred == NULL) { |
| 127 | failed = TRUE; |
| 128 | goto out; |
| 129 | } |
| 130 | |
| 131 | ftab->releaseCred = (RELEASE_CRED_FN_PTR)GETFUNC(gssLib, RELEASE_CRED); |
| 132 | if (ftab->releaseCred == NULL) { |
| 133 | failed = TRUE; |
| 134 | goto out; |
| 135 | } |
| 136 | |
| 137 | ftab->inquireCred = (INQUIRE_CRED_FN_PTR)GETFUNC(gssLib, INQUIRE_CRED); |
| 138 | if (ftab->inquireCred == NULL) { |
| 139 | failed = TRUE; |
| 140 | goto out; |
| 141 | } |
| 142 | |
| 143 | ftab->importSecContext = (IMPORT_SEC_CONTEXT_FN_PTR) |
| 144 | GETFUNC(gssLib, IMPORT_SEC_CONTEXT); |
| 145 | if (ftab->importSecContext == NULL) { |
| 146 | failed = TRUE; |
| 147 | goto out; |
| 148 | } |
| 149 | |
| 150 | ftab->initSecContext = (INIT_SEC_CONTEXT_FN_PTR) |
| 151 | GETFUNC(gssLib, INIT_SEC_CONTEXT); |
| 152 | if (ftab->initSecContext == NULL) { |
| 153 | failed = TRUE; |
| 154 | goto out; |
| 155 | } |
| 156 | |
| 157 | ftab->acceptSecContext = (ACCEPT_SEC_CONTEXT_FN_PTR) |
| 158 | GETFUNC(gssLib, ACCEPT_SEC_CONTEXT); |
| 159 | if (ftab->acceptSecContext == NULL) { |
| 160 | failed = TRUE; |
| 161 | goto out; |
| 162 | } |
| 163 | |
| 164 | ftab->inquireContext = (INQUIRE_CONTEXT_FN_PTR) |
| 165 | GETFUNC(gssLib, INQUIRE_CONTEXT); |
| 166 | if (ftab->inquireContext == NULL) { |
| 167 | failed = TRUE; |
| 168 | goto out; |
| 169 | } |
| 170 | |
| 171 | ftab->deleteSecContext = (DELETE_SEC_CONTEXT_FN_PTR) |
| 172 | GETFUNC(gssLib, DELETE_SEC_CONTEXT); |
| 173 | if (ftab->deleteSecContext == NULL) { |
| 174 | failed = TRUE; |
| 175 | goto out; |
| 176 | } |
| 177 | |
| 178 | ftab->contextTime = (CONTEXT_TIME_FN_PTR)GETFUNC(gssLib, CONTEXT_TIME); |
| 179 | if (ftab->contextTime == NULL) { |
| 180 | failed = TRUE; |
| 181 | goto out; |
| 182 | } |
| 183 | |
| 184 | ftab->wrapSizeLimit = (WRAP_SIZE_LIMIT_FN_PTR) |
| 185 | GETFUNC(gssLib, WRAP_SIZE_LIMIT); |
| 186 | if (ftab->wrapSizeLimit == NULL) { |
| 187 | failed = TRUE; |
| 188 | goto out; |
| 189 | } |
| 190 | |
| 191 | ftab->exportSecContext = (EXPORT_SEC_CONTEXT_FN_PTR) |
| 192 | GETFUNC(gssLib, EXPORT_SEC_CONTEXT); |
| 193 | if (ftab->exportSecContext == NULL) { |
| 194 | failed = TRUE; |
| 195 | goto out; |
| 196 | } |
| 197 | |
| 198 | ftab->getMic = (GET_MIC_FN_PTR)GETFUNC(gssLib, GET_MIC); |
| 199 | if (ftab->getMic == NULL) { |
| 200 | failed = TRUE; |
| 201 | goto out; |
| 202 | } |
| 203 | |
| 204 | ftab->verifyMic = (VERIFY_MIC_FN_PTR)GETFUNC(gssLib, VERIFY_MIC); |
| 205 | if (ftab->verifyMic == NULL) { |
| 206 | failed = TRUE; |
| 207 | goto out; |
| 208 | } |
| 209 | |
| 210 | ftab->wrap = (WRAP_FN_PTR)GETFUNC(gssLib, WRAP); |
| 211 | if (ftab->wrap == NULL) { |
| 212 | failed = TRUE; |
| 213 | goto out; |
| 214 | } |
| 215 | |
| 216 | ftab->unwrap = (UNWRAP_FN_PTR)GETFUNC(gssLib, UNWRAP); |
| 217 | if (ftab->unwrap == NULL) { |
| 218 | failed = TRUE; |
| 219 | goto out; |
| 220 | } |
| 221 | |
| 222 | ftab->indicateMechs = (INDICATE_MECHS_FN_PTR)GETFUNC(gssLib, INDICATE_MECHS); |
| 223 | if (ftab->indicateMechs == NULL) { |
| 224 | failed = TRUE; |
| 225 | goto out; |
| 226 | } |
| 227 | |
| 228 | ftab->inquireNamesForMech = (INQUIRE_NAMES_FOR_MECH_FN_PTR) |
| 229 | GETFUNC(gssLib, INQUIRE_NAMES_FOR_MECH); |
| 230 | if (ftab->inquireNamesForMech == NULL) { |
| 231 | failed = TRUE; |
| 232 | goto out; |
| 233 | } |
| 234 | |
| 235 | ftab->addOidSetMember = (ADD_OID_SET_MEMBER_FN_PTR) |
| 236 | GETFUNC(gssLib, ADD_OID_SET_MEMBER); |
| 237 | if (ftab->addOidSetMember == NULL) { |
| 238 | failed = TRUE; |
| 239 | goto out; |
| 240 | } |
| 241 | |
| 242 | ftab->displayStatus = (DISPLAY_STATUS_FN_PTR) |
| 243 | GETFUNC(gssLib, DISPLAY_STATUS); |
| 244 | if (ftab->displayStatus == NULL) { |
| 245 | failed = TRUE; |
| 246 | goto out; |
| 247 | } |
| 248 | |
| 249 | ftab->createEmptyOidSet = (CREATE_EMPTY_OID_SET_FN_PTR) |
| 250 | GETFUNC(gssLib, CREATE_EMPTY_OID_SET); |
| 251 | if (ftab->createEmptyOidSet == NULL) { |
| 252 | failed = TRUE; |
| 253 | goto out; |
| 254 | } |
| 255 | |
| 256 | ftab->releaseOidSet = (RELEASE_OID_SET_FN_PTR) |
| 257 | GETFUNC(gssLib, RELEASE_OID_SET); |
| 258 | if (ftab->releaseOidSet == NULL) { |
| 259 | failed = TRUE; |
| 260 | goto out; |
| 261 | } |
| 262 | |
| 263 | ftab->releaseBuffer = (RELEASE_BUFFER_FN_PTR) |
| 264 | GETFUNC(gssLib, RELEASE_BUFFER); |
| 265 | if (ftab->releaseBuffer == NULL) { |
| 266 | failed = TRUE; |
| 267 | goto out; |
| 268 | } |
| 269 | |
| 270 | ftab->mechs = GSS_C_NO_OID_SET; |
| 271 | major = (*ftab->indicateMechs)(&minor, &(ftab->mechs)); |
| 272 | if (ftab->mechs == NULL || ftab->mechs == GSS_C_NO_OID_SET) { |
| 273 | failed = TRUE; |
| 274 | goto out; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | out: |
| 279 | if (failed == TRUE) { |
| 280 | if (gssLib != NULL) CLOSELIB(gssLib); |
| 281 | if (ftab != NULL) free(ftab); |
| 282 | } |
| 283 | return failed; |
| 284 | } |
| 285 | |