Path: blob/master/src/java.security.jgss/share/native/libj2gss/NativeFunc.c
41149 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdio.h>26#include <stdlib.h>27#include "NativeFunc.h"2829/* global GSS function table */30GSS_FUNCTION_TABLE_PTR ftab;3132/* standard GSS method names (ordering is from mapfile) */33static const char RELEASE_NAME[] = "gss_release_name";34static const char IMPORT_NAME[] = "gss_import_name";35static const char COMPARE_NAME[] = "gss_compare_name";36static const char CANONICALIZE_NAME[] = "gss_canonicalize_name";37static const char EXPORT_NAME[] = "gss_export_name";38static const char DISPLAY_NAME[] = "gss_display_name";39static const char ACQUIRE_CRED[] = "gss_acquire_cred";40static const char RELEASE_CRED[] = "gss_release_cred";41static const char INQUIRE_CRED[] = "gss_inquire_cred";42static const char IMPORT_SEC_CONTEXT[] = "gss_import_sec_context";43static const char INIT_SEC_CONTEXT[] = "gss_init_sec_context";44static const char ACCEPT_SEC_CONTEXT[] = "gss_accept_sec_context";45static const char INQUIRE_CONTEXT[] = "gss_inquire_context";46static const char DELETE_SEC_CONTEXT[] = "gss_delete_sec_context";47static const char CONTEXT_TIME[] = "gss_context_time";48static const char WRAP_SIZE_LIMIT[] = "gss_wrap_size_limit";49static const char EXPORT_SEC_CONTEXT[] = "gss_export_sec_context";50static const char GET_MIC[] = "gss_get_mic";51static const char VERIFY_MIC[] = "gss_verify_mic";52static const char WRAP[] = "gss_wrap";53static const char UNWRAP[] = "gss_unwrap";54static const char INDICATE_MECHS[] = "gss_indicate_mechs";55static const char INQUIRE_NAMES_FOR_MECH[] = "gss_inquire_names_for_mech";5657/* additional GSS methods not public thru mapfile */5859static const char ADD_OID_SET_MEMBER[] = "gss_add_oid_set_member";60static const char DISPLAY_STATUS[] = "gss_display_status";61static const char CREATE_EMPTY_OID_SET[] = "gss_create_empty_oid_set";62static const char RELEASE_OID_SET[] = "gss_release_oid_set";63static const char RELEASE_BUFFER[] = "gss_release_buffer";6465/**66* Initialize native GSS function pointers67*/68int loadNative(const char *libName) {6970void *gssLib;71int failed;72OM_uint32 minor, major;7374ftab = NULL;75failed = FALSE;7677gssLib = GETLIB(libName);78if (gssLib == NULL) {79failed = TRUE;80goto out;81}8283/* global function table instance */84ftab = (GSS_FUNCTION_TABLE_PTR)malloc(sizeof(GSS_FUNCTION_TABLE));85if (ftab == NULL) {86failed = TRUE;87goto out;88}8990ftab->releaseName = (RELEASE_NAME_FN_PTR)GETFUNC(gssLib, RELEASE_NAME);91if (ftab->releaseName == NULL) {92failed = TRUE;93goto out;94}9596ftab->importName = (IMPORT_NAME_FN_PTR)GETFUNC(gssLib, IMPORT_NAME);97if (ftab->importName == NULL) {98failed = TRUE;99goto out;100}101102ftab->compareName = (COMPARE_NAME_FN_PTR)GETFUNC(gssLib, COMPARE_NAME);103if (ftab->compareName == NULL) {104failed = TRUE;105goto out;106}107108ftab->canonicalizeName = (CANONICALIZE_NAME_FN_PTR)109GETFUNC(gssLib, CANONICALIZE_NAME);110if (ftab->canonicalizeName == NULL) {111failed = TRUE;112goto out;113}114115ftab->exportName = (EXPORT_NAME_FN_PTR)GETFUNC(gssLib, EXPORT_NAME);116if (ftab->exportName == NULL) {117failed = TRUE;118goto out;119}120121ftab->displayName = (DISPLAY_NAME_FN_PTR)GETFUNC(gssLib, DISPLAY_NAME);122if (ftab->displayName == NULL) {123failed = TRUE;124goto out;125}126127ftab->acquireCred = (ACQUIRE_CRED_FN_PTR)GETFUNC(gssLib, ACQUIRE_CRED);128if (ftab->acquireCred == NULL) {129failed = TRUE;130goto out;131}132133ftab->releaseCred = (RELEASE_CRED_FN_PTR)GETFUNC(gssLib, RELEASE_CRED);134if (ftab->releaseCred == NULL) {135failed = TRUE;136goto out;137}138139ftab->inquireCred = (INQUIRE_CRED_FN_PTR)GETFUNC(gssLib, INQUIRE_CRED);140if (ftab->inquireCred == NULL) {141failed = TRUE;142goto out;143}144145ftab->importSecContext = (IMPORT_SEC_CONTEXT_FN_PTR)146GETFUNC(gssLib, IMPORT_SEC_CONTEXT);147if (ftab->importSecContext == NULL) {148failed = TRUE;149goto out;150}151152ftab->initSecContext = (INIT_SEC_CONTEXT_FN_PTR)153GETFUNC(gssLib, INIT_SEC_CONTEXT);154if (ftab->initSecContext == NULL) {155failed = TRUE;156goto out;157}158159ftab->acceptSecContext = (ACCEPT_SEC_CONTEXT_FN_PTR)160GETFUNC(gssLib, ACCEPT_SEC_CONTEXT);161if (ftab->acceptSecContext == NULL) {162failed = TRUE;163goto out;164}165166ftab->inquireContext = (INQUIRE_CONTEXT_FN_PTR)167GETFUNC(gssLib, INQUIRE_CONTEXT);168if (ftab->inquireContext == NULL) {169failed = TRUE;170goto out;171}172173ftab->deleteSecContext = (DELETE_SEC_CONTEXT_FN_PTR)174GETFUNC(gssLib, DELETE_SEC_CONTEXT);175if (ftab->deleteSecContext == NULL) {176failed = TRUE;177goto out;178}179180ftab->contextTime = (CONTEXT_TIME_FN_PTR)GETFUNC(gssLib, CONTEXT_TIME);181if (ftab->contextTime == NULL) {182failed = TRUE;183goto out;184}185186ftab->wrapSizeLimit = (WRAP_SIZE_LIMIT_FN_PTR)187GETFUNC(gssLib, WRAP_SIZE_LIMIT);188if (ftab->wrapSizeLimit == NULL) {189failed = TRUE;190goto out;191}192193ftab->exportSecContext = (EXPORT_SEC_CONTEXT_FN_PTR)194GETFUNC(gssLib, EXPORT_SEC_CONTEXT);195if (ftab->exportSecContext == NULL) {196failed = TRUE;197goto out;198}199200ftab->getMic = (GET_MIC_FN_PTR)GETFUNC(gssLib, GET_MIC);201if (ftab->getMic == NULL) {202failed = TRUE;203goto out;204}205206ftab->verifyMic = (VERIFY_MIC_FN_PTR)GETFUNC(gssLib, VERIFY_MIC);207if (ftab->verifyMic == NULL) {208failed = TRUE;209goto out;210}211212ftab->wrap = (WRAP_FN_PTR)GETFUNC(gssLib, WRAP);213if (ftab->wrap == NULL) {214failed = TRUE;215goto out;216}217218ftab->unwrap = (UNWRAP_FN_PTR)GETFUNC(gssLib, UNWRAP);219if (ftab->unwrap == NULL) {220failed = TRUE;221goto out;222}223224ftab->indicateMechs = (INDICATE_MECHS_FN_PTR)GETFUNC(gssLib, INDICATE_MECHS);225if (ftab->indicateMechs == NULL) {226failed = TRUE;227goto out;228}229230ftab->inquireNamesForMech = (INQUIRE_NAMES_FOR_MECH_FN_PTR)231GETFUNC(gssLib, INQUIRE_NAMES_FOR_MECH);232if (ftab->inquireNamesForMech == NULL) {233failed = TRUE;234goto out;235}236237ftab->addOidSetMember = (ADD_OID_SET_MEMBER_FN_PTR)238GETFUNC(gssLib, ADD_OID_SET_MEMBER);239if (ftab->addOidSetMember == NULL) {240failed = TRUE;241goto out;242}243244ftab->displayStatus = (DISPLAY_STATUS_FN_PTR)245GETFUNC(gssLib, DISPLAY_STATUS);246if (ftab->displayStatus == NULL) {247failed = TRUE;248goto out;249}250251ftab->createEmptyOidSet = (CREATE_EMPTY_OID_SET_FN_PTR)252GETFUNC(gssLib, CREATE_EMPTY_OID_SET);253if (ftab->createEmptyOidSet == NULL) {254failed = TRUE;255goto out;256}257258ftab->releaseOidSet = (RELEASE_OID_SET_FN_PTR)259GETFUNC(gssLib, RELEASE_OID_SET);260if (ftab->releaseOidSet == NULL) {261failed = TRUE;262goto out;263}264265ftab->releaseBuffer = (RELEASE_BUFFER_FN_PTR)266GETFUNC(gssLib, RELEASE_BUFFER);267if (ftab->releaseBuffer == NULL) {268failed = TRUE;269goto out;270}271272ftab->mechs = GSS_C_NO_OID_SET;273major = (*ftab->indicateMechs)(&minor, &(ftab->mechs));274if (ftab->mechs == NULL || ftab->mechs == GSS_C_NO_OID_SET) {275failed = TRUE;276goto out;277}278279280out:281if (failed == TRUE) {282if (gssLib != NULL) CLOSELIB(gssLib);283if (ftab != NULL) free(ftab);284}285return failed;286}287288289