2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * This file contains functions to initialize the gssapi library and
2N/A * load mechanism libraries.
2N/A *
2N/A * It also contain functions requiring direct access to the mechanism's
2N/A * list (gss_inidicate_mechs and gss_release_oid) as well as support
2N/A * functions which translate the mechanism strings to oids and vise versa.
2N/A *
2N/A * The mechanism libraries are loaded on demand. This is triggered
2N/A * through the get_mechanism function call.
2N/A *
2N/A * Updates to the mechList are performed with the following restrictions:
2N/A * - once a library is loaded, none of the fields are updated
2N/A * - existing entiries for non-loaded mechs, will have the
2N/A * library and kernel module names updated only
2N/A * (i.e. the mech oid and mech name will not be updated)
2N/A */
2N/A
2N/A#include <mglueP.h>
2N/A#include "gssapiP_generic.h"
2N/A#include <stdio.h>
2N/A#include <syslog.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <sys/stat.h>
2N/A#include <ctype.h>
2N/A#include <errno.h>
2N/A#include <synch.h>
2N/A#include <dlfcn.h>
2N/A#include <libintl.h>
2N/A
2N/A
2N/A#ifndef TEXT_DOMAIN
2N/A#error TEXT_DOMAIN not defined
2N/A#endif
2N/A
2N/A#define MECH_CONF "/etc/gss/mech"
2N/A
2N/A#define MECH_LIB_PREFIX1 "/usr/lib/"
2N/A
2N/A/*
2N/A * This #ifdef mess figures out if we are to be compiled into
2N/A * a sparcv9/lp64 binary for the purposes of figuring the absolute location
2N/A * of gss-api mechanism modules.
2N/A */
2N/A#ifdef _LP64
2N/A
2N/A#ifdef __sparc
2N/A
2N/A#define MECH_LIB_PREFIX2 "sparcv9/"
2N/A
2N/A#elif defined(__amd64)
2N/A
2N/A#define MECH_LIB_PREFIX2 "amd64/"
2N/A
2N/A#else /* __sparc */
2N/A
2N/Ayou need to define where under /usr the LP64 libraries live for this platform
2N/A
2N/A#endif /* __sparc */
2N/A
2N/A#else /* _LP64 */
2N/A
2N/A#define MECH_LIB_PREFIX2 ""
2N/A
2N/A#endif /* _LP64 */
2N/A
2N/A#define MECH_LIB_DIR "gss/"
2N/A
2N/A#define MECH_LIB_PREFIX MECH_LIB_PREFIX1 MECH_LIB_PREFIX2 MECH_LIB_DIR
2N/A
2N/A
2N/A#ifndef MECH_SYM
2N/A#define MECH_SYM "gss_mech_initialize"
2N/A#endif
2N/A
2N/A#define M_DEFAULT "default"
2N/A
2N/A/* Local functions */
2N/Astatic gss_mech_info searchMechList(const gss_OID);
2N/Astatic void loadConfigFile(const char *);
2N/Astatic void updateMechList(void);
2N/A
2N/A
2N/A/*
2N/A * list of mechanism libraries and their entry points.
2N/A * the list also maintains state of the mech libraries (loaded or not).
2N/A */
2N/Astatic gss_mech_info g_mechList = NULL;
2N/Astatic gss_mech_info g_mechListTail = NULL;
2N/Astatic mutex_t g_mechListLock;
2N/Astatic time_t g_confFileModTime = (time_t)0;
2N/A
2N/A/*
2N/A * function used to reclaim the memory used by a gss_OID structure.
2N/A * This routine requires direct access to the mechList.
2N/A */
2N/AOM_uint32
2N/Agss_release_oid(minor_status, oid)
2N/AOM_uint32 *minor_status;
2N/Agss_OID *oid;
2N/A{
2N/A OM_uint32 major;
2N/A gss_mech_info aMech = g_mechList;
2N/A
2N/A if (minor_status == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A *minor_status = 0;
2N/A
2N/A while (aMech != NULL) {
2N/A
2N/A /*
2N/A * look through the loaded mechanism libraries for
2N/A * gss_internal_release_oid until one returns success.
2N/A * gss_internal_release_oid will only return success when
2N/A * the OID was recognized as an internal mechanism OID. if no
2N/A * mechanisms recognize the OID, then call the generic version.
2N/A */
2N/A
2N/A /*
2N/A * we can walk the mechanism list without a mutex, because we
2N/A * are only looking at fields which once read will never change.
2N/A * Mechanism entries are always added to the end, and as
2N/A * complete entries.
2N/A */
2N/A if (aMech->mech && aMech->mech->gss_internal_release_oid) {
2N/A major = aMech->mech->gss_internal_release_oid(
2N/A minor_status, oid);
2N/A if (major == GSS_S_COMPLETE)
2N/A return (GSS_S_COMPLETE);
2N/A map_error(minor_status, aMech->mech);
2N/A }
2N/A aMech = aMech->next;
2N/A } /* while */
2N/A
2N/A return (generic_gss_release_oid(minor_status, oid));
2N/A} /* gss_release_oid */
2N/A
2N/A
2N/A/*
2N/A * this function will return an oid set indicating available mechanisms.
2N/A * The set returned is based on configuration file entries and
2N/A * NOT on the loaded mechanisms. This function does not check if any
2N/A * of these can actually be loaded.
2N/A * This routine needs direct access to the mechanism list.
2N/A * To avoid reading the configuration file each call, we will save a
2N/A * a mech oid set, and only update it once the file has changed.
2N/A */
2N/Astatic time_t g_mechSetTime = (time_t)0;
2N/Astatic gss_OID_set_desc g_mechSet = { 0, NULL };
2N/Astatic mutex_t g_mechSetLock;
2N/A
2N/A
2N/AOM_uint32
2N/Agss_indicate_mechs(minorStatus, mechSet)
2N/AOM_uint32 *minorStatus;
2N/Agss_OID_set *mechSet;
2N/A{
2N/A gss_mech_info mList;
2N/A char *fileName;
2N/A struct stat fileInfo;
2N/A int count, i, j;
2N/A gss_OID curItem;
2N/A
2N/A /* Initialize outputs. */
2N/A
2N/A if (minorStatus != NULL)
2N/A *minorStatus = 0;
2N/A
2N/A if (mechSet != NULL)
2N/A *mechSet = GSS_C_NO_OID_SET;
2N/A
2N/A /* Validate arguments. */
2N/A if (minorStatus == NULL || mechSet == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A fileName = MECH_CONF;
2N/A
2N/A /*
2N/A * If we have already computed the mechanisms supported and if it
2N/A * is still valid; make a copy and return to caller,
2N/A * otherwise build it first.
2N/A */
2N/A if ((stat(fileName, &fileInfo) == 0 &&
2N/A fileInfo.st_mtime > g_mechSetTime)) {
2N/A /*
2N/A * lock the mutex since we will be updating
2N/A * the mechList structure
2N/A * we need to keep the lock while we build the mechanism list
2N/A * since we are accessing parts of the mechList which could be
2N/A * modified.
2N/A */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A
2N/A /*
2N/A * this checks for the case when we need to re-construct the
2N/A * g_mechSet structure, but the mechanism list is upto date
2N/A * (because it has been read by someone calling
2N/A * __gss_get_mechanism)
2N/A */
2N/A if (fileInfo.st_mtime > g_confFileModTime)
2N/A {
2N/A g_confFileModTime = fileInfo.st_mtime;
2N/A loadConfigFile(fileName);
2N/A }
2N/A
2N/A /*
2N/A * we need to lock the mech set so that no one else will
2N/A * try to read it as we are re-creating it
2N/A */
2N/A (void) mutex_lock(&g_mechSetLock);
2N/A
2N/A /* if the oid list already exists we must free it first */
2N/A if (g_mechSet.count != 0) {
2N/A for (i = 0; i < g_mechSet.count; i++)
2N/A free(g_mechSet.elements[i].elements);
2N/A free(g_mechSet.elements);
2N/A g_mechSet.elements = NULL;
2N/A g_mechSet.count = 0;
2N/A }
2N/A
2N/A /* determine how many elements to have in the list */
2N/A mList = g_mechList;
2N/A count = 0;
2N/A while (mList != NULL) {
2N/A count++;
2N/A mList = mList->next;
2N/A }
2N/A
2N/A /* this should always be true, but.... */
2N/A if (count > 0) {
2N/A g_mechSet.elements =
2N/A (gss_OID) calloc(count, sizeof (gss_OID_desc));
2N/A if (g_mechSet.elements == NULL) {
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return (GSS_S_FAILURE);
2N/A }
2N/A
2N/A (void) memset(g_mechSet.elements, 0,
2N/A count * sizeof (gss_OID_desc));
2N/A
2N/A /* now copy each oid element */
2N/A g_mechSet.count = count;
2N/A count = 0;
2N/A mList = g_mechList;
2N/A while (mList != NULL) {
2N/A curItem = &(g_mechSet.elements[count]);
2N/A curItem->elements = (void*)
2N/A malloc(mList->mech_type->length);
2N/A if (curItem->elements == NULL) {
2N/A /*
2N/A * this is nasty - we must delete the
2N/A * part of the array already copied
2N/A */
2N/A for (i = 0; i < count; i++) {
2N/A free(g_mechSet.elements[i].
2N/A elements);
2N/A }
2N/A free(g_mechSet.elements);
2N/A g_mechSet.count = 0;
2N/A g_mechSet.elements = NULL;
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return (GSS_S_FAILURE);
2N/A }
2N/A g_OID_copy(curItem, mList->mech_type);
2N/A count++;
2N/A mList = mList->next;
2N/A }
2N/A }
2N/A
2N/A g_mechSetTime = fileInfo.st_mtime;
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A } /* if g_mechSet is out of date or not initialized */
2N/A
2N/A /*
2N/A * the mech set is created and it is up to date
2N/A * so just copy it to caller
2N/A */
2N/A if ((*mechSet =
2N/A (gss_OID_set) malloc(sizeof (gss_OID_set_desc))) == NULL)
2N/A {
2N/A return (GSS_S_FAILURE);
2N/A }
2N/A
2N/A /*
2N/A * need to lock the g_mechSet in case someone tries to update it while
2N/A * I'm copying it.
2N/A */
2N/A (void) mutex_lock(&g_mechSetLock);
2N/A
2N/A /* allocate space for the oid structures */
2N/A if (((*mechSet)->elements =
2N/A (void*) calloc(g_mechSet.count, sizeof (gss_OID_desc)))
2N/A == NULL)
2N/A {
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A free(*mechSet);
2N/A *mechSet = NULL;
2N/A return (GSS_S_FAILURE);
2N/A }
2N/A
2N/A /* now copy the oid structures */
2N/A (void) memcpy((*mechSet)->elements, g_mechSet.elements,
2N/A g_mechSet.count * sizeof (gss_OID_desc));
2N/A
2N/A (*mechSet)->count = g_mechSet.count;
2N/A
2N/A /* still need to copy each of the oid elements arrays */
2N/A for (i = 0; i < (*mechSet)->count; i++) {
2N/A curItem = &((*mechSet)->elements[i]);
2N/A curItem->elements =
2N/A (void *) malloc(g_mechSet.elements[i].length);
2N/A if (curItem->elements == NULL) {
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A /*
2N/A * must still free the allocated elements for
2N/A * each allocated gss_OID_desc
2N/A */
2N/A for (j = 0; j < i; j++) {
2N/A free((*mechSet)->elements[j].elements);
2N/A }
2N/A free((*mechSet)->elements);
2N/A free(*mechSet);
2N/A *mechSet = NULL;
2N/A return (GSS_S_FAILURE);
2N/A }
2N/A g_OID_copy(curItem, &g_mechSet.elements[i]);
2N/A }
2N/A (void) mutex_unlock(&g_mechSetLock);
2N/A return (GSS_S_COMPLETE);
2N/A} /* gss_indicate_mechs */
2N/A
2N/A/*
2N/A * this function has been added for use by modules that need to
2N/A * know what (if any) optional parameters are supplied in the
2N/A * config file (MECH_CONF).
2N/A * It will return the option string for a specified mechanism.
2N/A * caller is responsible for freeing the memory
2N/A */
2N/Achar *
2N/A__gss_get_modOptions(oid)
2N/Aconst gss_OID oid;
2N/A{
2N/A gss_mech_info aMech;
2N/A char *modOptions = NULL;
2N/A
2N/A /* make sure we have fresh data */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A /* searching the list does not require a lock */
2N/A if ((aMech = searchMechList(oid)) == NULL ||
2N/A aMech->optionStr == NULL) {
2N/A return (NULL);
2N/A }
2N/A
2N/A /*
2N/A * need to obtain a lock on this structure in case someone else
2N/A * will try to update it during the copy
2N/A */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A if (aMech->optionStr)
2N/A modOptions = strdup(aMech->optionStr);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A return (modOptions);
2N/A} /* __gss_get_modOptions */
2N/A
2N/A/*
2N/A * this function has been added for use by gssd.
2N/A * It will return the kernel module name for a specified mechanism.
2N/A * caller is responsible for freeing the memory
2N/A */
2N/Achar *
2N/A__gss_get_kmodName(oid)
2N/Aconst gss_OID oid;
2N/A{
2N/A gss_mech_info aMech;
2N/A char *kmodName = NULL;
2N/A
2N/A /* make sure we have fresh data */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A /* searching the list does not require a lock */
2N/A if ((aMech = searchMechList(oid)) == NULL || aMech->kmodName == NULL) {
2N/A return (NULL);
2N/A }
2N/A
2N/A /*
2N/A * need to obtain a lock on this structure in case someone else
2N/A * will try to update it during the copy
2N/A */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A if (aMech->kmodName)
2N/A kmodName = strdup(aMech->kmodName);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A return (kmodName);
2N/A} /* __gss_get_kmodName */
2N/A
2N/A
2N/A/*
2N/A * given a mechanism string return the mechanism oid
2N/A */
2N/AOM_uint32
2N/A__gss_mech_to_oid(const char *mechStr, gss_OID* oid)
2N/A{
2N/A gss_mech_info aMech;
2N/A
2N/A if (oid == NULL)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A *oid = GSS_C_NULL_OID;
2N/A
2N/A if ((mechStr == NULL) || (strlen(mechStr) == 0) ||
2N/A (strcasecmp(mechStr, M_DEFAULT) == 0))
2N/A return (GSS_S_COMPLETE);
2N/A
2N/A /* ensure we have fresh data */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A aMech = g_mechList;
2N/A
2N/A /* no lock required - only looking at fields that are not updated */
2N/A while (aMech != NULL) {
2N/A if ((aMech->mechNameStr) &&
2N/A strcmp(aMech->mechNameStr, mechStr) == 0) {
2N/A *oid = aMech->mech_type;
2N/A return (GSS_S_COMPLETE);
2N/A }
2N/A aMech = aMech->next;
2N/A }
2N/A return (GSS_S_FAILURE);
2N/A} /* __gss_mech_to_oid */
2N/A
2N/A
2N/A/*
2N/A * Given the mechanism oid, return the readable mechanism name
2N/A * associated with that oid from the mech config file
2N/A * (/etc/gss/mech).
2N/A */
2N/Aconst char *
2N/A__gss_oid_to_mech(const gss_OID oid)
2N/A{
2N/A gss_mech_info aMech;
2N/A
2N/A if (oid == GSS_C_NULL_OID)
2N/A return (M_DEFAULT);
2N/A
2N/A /* ensure we have fresh data */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A if ((aMech = searchMechList(oid)) == NULL)
2N/A return (NULL);
2N/A
2N/A return (aMech->mechNameStr);
2N/A} /* __gss_oid_to_mech */
2N/A
2N/A
2N/A/*
2N/A * return a list of mechanism strings supported
2N/A * upon return the array is terminated with a NULL entry
2N/A */
2N/AOM_uint32
2N/A__gss_get_mechanisms(char *mechArray[], int arrayLen)
2N/A{
2N/A gss_mech_info aMech;
2N/A int i;
2N/A
2N/A if (mechArray == NULL || arrayLen < 1)
2N/A return (GSS_S_CALL_INACCESSIBLE_WRITE);
2N/A
2N/A /* ensure we have fresh data */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A aMech = g_mechList;
2N/A
2N/A /* no lock required - only looking at fields that are not updated */
2N/A for (i = 1; i < arrayLen; i++) {
2N/A if (aMech != NULL) {
2N/A *mechArray = aMech->mechNameStr;
2N/A mechArray++;
2N/A aMech = aMech->next;
2N/A } else
2N/A break;
2N/A }
2N/A *mechArray = NULL;
2N/A return (GSS_S_COMPLETE);
2N/A} /* gss_get_mechanisms */
2N/A
2N/A
2N/A/*
2N/A * determines if the mechList needs to be updated from file
2N/A * and performs the update.
2N/A * this functions must be called with a lock of g_mechListLock
2N/A */
2N/Astatic void
2N/AupdateMechList(void)
2N/A{
2N/A char *fileName;
2N/A struct stat fileInfo;
2N/A
2N/A fileName = MECH_CONF;
2N/A
2N/A /* check if mechList needs updating */
2N/A if (stat(fileName, &fileInfo) == 0 &&
2N/A (fileInfo.st_mtime > g_confFileModTime)) {
2N/A loadConfigFile(fileName);
2N/A g_confFileModTime = fileInfo.st_mtime;
2N/A }
2N/A} /* updateMechList */
2N/A
2N/A
2N/A/*
2N/A * given the mechanism type, return the mechanism structure
2N/A * containing the mechanism library entry points.
2N/A * will return NULL if mech type is not found
2N/A * This function will also trigger the loading of the mechanism
2N/A * module if it has not been already loaded.
2N/A */
2N/Agss_mechanism
2N/A__gss_get_mechanism(oid)
2N/Aconst gss_OID oid;
2N/A{
2N/A gss_mech_info aMech;
2N/A gss_mechanism (*sym)(const gss_OID);
2N/A void *dl;
2N/A
2N/A /* check if the mechanism is already loaded */
2N/A if ((aMech = searchMechList(oid)) != NULL && aMech->mech) {
2N/A return (aMech->mech);
2N/A }
2N/A
2N/A /*
2N/A * might need to re-read the configuration file before loading
2N/A * the mechanism to ensure we have the latest info.
2N/A */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A updateMechList();
2N/A
2N/A aMech = searchMechList(oid);
2N/A
2N/A /* is the mechanism present in the list ? */
2N/A if (aMech == NULL) {
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return ((gss_mechanism)NULL);
2N/A }
2N/A
2N/A /* has another thread loaded the mech */
2N/A if (aMech->mech) {
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return (aMech->mech);
2N/A }
2N/A
2N/A /* we found the mechanism, but it is not loaded */
2N/A if ((dl = dlopen(aMech->uLibName, RTLD_NOW)) == NULL) {
2N/A (void) syslog(LOG_INFO, "libgss dlopen(%s): %s\n",
2N/A aMech->uLibName, dlerror());
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return ((gss_mechanism)NULL);
2N/A }
2N/A
2N/A if ((sym = (gss_mechanism (*)(const gss_OID))dlsym(dl, MECH_SYM))
2N/A == NULL) {
2N/A (void) dlclose(dl);
2N/A (void) syslog(LOG_INFO, "unable to initialize mechanism"
2N/A " library [%s]\n", aMech->uLibName);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return ((gss_mechanism)NULL);
2N/A }
2N/A
2N/A /* Call the symbol to get the mechanism table */
2N/A aMech->mech = (*sym)(aMech->mech_type);
2N/A
2N/A if (aMech->mech == NULL) {
2N/A (void) dlclose(dl);
2N/A (void) syslog(LOG_INFO, "unable to initialize mechanism"
2N/A " library [%s]\n", aMech->uLibName);
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return ((gss_mechanism)NULL);
2N/A }
2N/A
2N/A aMech->dl_handle = dl;
2N/A
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A return (aMech->mech);
2N/A} /* __gss_get_mechanism */
2N/A
2N/Agss_mechanism_ext
2N/A__gss_get_mechanism_ext(oid)
2N/Aconst gss_OID oid;
2N/A{
2N/A gss_mech_info aMech;
2N/A gss_mechanism_ext mech_ext;
2N/A
2N/A /* check if the mechanism is already loaded */
2N/A if ((aMech = searchMechList(oid)) != NULL && aMech->mech_ext != NULL)
2N/A return (aMech->mech_ext);
2N/A
2N/A if (__gss_get_mechanism(oid) == NULL)
2N/A return (NULL);
2N/A
2N/A if (aMech->dl_handle == NULL)
2N/A return (NULL);
2N/A
2N/A /* Load the gss_config_ext struct for this mech */
2N/A
2N/A mech_ext = (gss_mechanism_ext)malloc(sizeof (struct gss_config_ext));
2N/A
2N/A if (mech_ext == NULL)
2N/A return (NULL);
2N/A
2N/A /*
2N/A * dlsym() the mech's 'method' functions for the extended APIs
2N/A *
2N/A * NOTE: Until the void *context argument is removed from the
2N/A * SPI method functions' signatures it will be necessary to have
2N/A * different function pointer typedefs and function names for
2N/A * the SPI methods than for the API. When this argument is
2N/A * removed it will be possible to rename gss_*_sfct to gss_*_fct
2N/A * and and gssspi_* to gss_*.
2N/A */
2N/A mech_ext->gss_acquire_cred_with_password =
2N/A (gss_acquire_cred_with_password_sfct)dlsym(aMech->dl_handle,
2N/A "gssspi_acquire_cred_with_password");
2N/A
2N/A /* Set aMech->mech_ext */
2N/A (void) mutex_lock(&g_mechListLock);
2N/A
2N/A if (aMech->mech_ext == NULL)
2N/A aMech->mech_ext = mech_ext;
2N/A else
2N/A free(mech_ext); /* we raced and lost; don't leak */
2N/A
2N/A (void) mutex_unlock(&g_mechListLock);
2N/A
2N/A return (aMech->mech_ext);
2N/A
2N/A} /* __gss_get_mechanism_ext */
2N/A
2N/A
2N/A/*
2N/A * this routine is used for searching the list of mechanism data.
2N/A * it needs not be mutex protected because we only add new structures
2N/A * from the end and they are fully initialized before being added.
2N/A */
2N/Astatic gss_mech_info searchMechList(oid)
2N/Aconst gss_OID oid;
2N/A{
2N/A gss_mech_info aMech = g_mechList;
2N/A
2N/A /* if oid is null -> then get default which is the first in the list */
2N/A if (oid == GSS_C_NULL_OID)
2N/A return (aMech);
2N/A
2N/A while (aMech != NULL) {
2N/A if (g_OID_equal(aMech->mech_type, oid))
2N/A return (aMech);
2N/A aMech = aMech->next;
2N/A }
2N/A
2N/A /* none found */
2N/A return ((gss_mech_info) NULL);
2N/A} /* searchMechList */
2N/A
2N/A
2N/A/*
2N/A * loads the configuration file
2N/A * this is called while having a mutex lock on the mechanism list
2N/A * entries for libraries that have been loaded can't be modified
2N/A * mechNameStr and mech_type fields are not updated during updates
2N/A */
2N/Astatic void loadConfigFile(fileName)
2N/Aconst char *fileName;
2N/A{
2N/A char buffer[BUFSIZ], *oidStr, *oid, *sharedLib, *kernMod, *endp;
2N/A char *modOptions;
2N/A char sharedPath[sizeof (MECH_LIB_PREFIX) + BUFSIZ];
2N/A char *tmpStr;
2N/A FILE *confFile;
2N/A gss_OID mechOid;
2N/A gss_mech_info aMech, tmp;
2N/A OM_uint32 minor;
2N/A gss_buffer_desc oidBuf;
2N/A
2N/A if ((confFile = fopen(fileName, "rF")) == NULL) {
2N/A return;
2N/A }
2N/A
2N/A (void) memset(buffer, 0, sizeof (buffer));
2N/A while (fgets(buffer, BUFSIZ, confFile) != NULL) {
2N/A
2N/A /* ignore lines beginning with # */
2N/A if (*buffer == '#')
2N/A continue;
2N/A
2N/A /*
2N/A * find the first white-space character after
2N/A * the mechanism name
2N/A */
2N/A oidStr = buffer;
2N/A for (oid = buffer; *oid && !isspace(*oid); oid++);
2N/A
2N/A /* Now find the first non-white-space character */
2N/A if (*oid) {
2N/A *oid = '\0';
2N/A oid++;
2N/A while (*oid && isspace(*oid))
2N/A oid++;
2N/A }
2N/A
2N/A /*
2N/A * If that's all, then this is a corrupt entry. Skip it.
2N/A */
2N/A if (! *oid)
2N/A continue;
2N/A
2N/A /* Find the end of the oid and make sure it is NULL-ended */
2N/A for (endp = oid; *endp && !isspace(*endp); endp++)
2N/A ;
2N/A
2N/A if (*endp) {
2N/A *endp = '\0';
2N/A }
2N/A
2N/A /*
2N/A * check if an entry for this oid already exists
2N/A * if it does, and the library is already loaded then
2N/A * we can't modify it, so skip it
2N/A */
2N/A oidBuf.value = (void *)oid;
2N/A oidBuf.length = strlen(oid);
2N/A if (generic_gss_str_to_oid(&minor, &oidBuf, &mechOid)
2N/A != GSS_S_COMPLETE) {
2N/A (void) syslog(LOG_INFO, "invalid mechanism oid"
2N/A " [%s] in configuration file", oid);
2N/A continue;
2N/A }
2N/A
2N/A aMech = searchMechList(mechOid);
2N/A if (aMech && aMech->mech) {
2N/A free(mechOid->elements);
2N/A free(mechOid);
2N/A continue;
2N/A }
2N/A
2N/A /* Find the start of the shared lib name */
2N/A for (sharedLib = endp+1; *sharedLib && isspace(*sharedLib);
2N/A sharedLib++)
2N/A ;
2N/A
2N/A /*
2N/A * If that's all, then this is a corrupt entry. Skip it.
2N/A */
2N/A if (! *sharedLib) {
2N/A free(mechOid->elements);
2N/A free(mechOid);
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * Find the end of the shared lib name and make sure it is
2N/A * NULL-terminated.
2N/A */
2N/A for (endp = sharedLib; *endp && !isspace(*endp); endp++)
2N/A ;
2N/A
2N/A if (*endp) {
2N/A *endp = '\0';
2N/A }
2N/A
2N/A /* Find the start of the optional kernel module lib name */
2N/A for (kernMod = endp+1; *kernMod && isspace(*kernMod);
2N/A kernMod++)
2N/A ;
2N/A
2N/A /*
2N/A * If this item starts with a bracket "[", then
2N/A * it is not a kernel module, but is a list of
2N/A * options for the user module to parse later.
2N/A */
2N/A if (*kernMod && *kernMod != '[') {
2N/A /*
2N/A * Find the end of the shared lib name and make sure
2N/A * it is NULL-terminated.
2N/A */
2N/A for (endp = kernMod; *endp && !isspace(*endp); endp++)
2N/A ;
2N/A
2N/A if (*endp) {
2N/A *endp = '\0';
2N/A }
2N/A } else
2N/A kernMod = NULL;
2N/A
2N/A /* Find the start of the optional module options list */
2N/A for (modOptions = endp+1; *modOptions && isspace(*modOptions);
2N/A modOptions++);
2N/A
2N/A if (*modOptions == '[') {
2N/A /* move past the opening bracket */
2N/A for (modOptions = modOptions+1;
2N/A *modOptions && isspace(*modOptions);
2N/A modOptions++);
2N/A
2N/A /* Find the closing bracket */
2N/A for (endp = modOptions;
2N/A *endp && *endp != ']'; endp++);
2N/A
2N/A if (endp)
2N/A *endp = '\0';
2N/A
2N/A } else {
2N/A modOptions = NULL;
2N/A }
2N/A
2N/A (void) strcpy(sharedPath, MECH_LIB_PREFIX);
2N/A (void) strcat(sharedPath, sharedLib);
2N/A
2N/A /*
2N/A * are we creating a new mechanism entry or
2N/A * just modifying existing (non loaded) mechanism entry
2N/A */
2N/A if (aMech) {
2N/A /*
2N/A * delete any old values and set new
2N/A * mechNameStr and mech_type are not modified
2N/A */
2N/A if (aMech->kmodName) {
2N/A free(aMech->kmodName);
2N/A aMech->kmodName = NULL;
2N/A }
2N/A
2N/A if (aMech->optionStr) {
2N/A free(aMech->optionStr);
2N/A aMech->optionStr = NULL;
2N/A }
2N/A
2N/A if ((tmpStr = strdup(sharedPath)) != NULL) {
2N/A if (aMech->uLibName)
2N/A free(aMech->uLibName);
2N/A aMech->uLibName = tmpStr;
2N/A }
2N/A
2N/A if (kernMod) /* this is an optional parameter */
2N/A aMech->kmodName = strdup(kernMod);
2N/A
2N/A if (modOptions) /* optional module options */
2N/A aMech->optionStr = strdup(modOptions);
2N/A
2N/A /* the oid is already set */
2N/A free(mechOid->elements);
2N/A free(mechOid);
2N/A continue;
2N/A }
2N/A
2N/A /* adding a new entry */
2N/A aMech = malloc(sizeof (struct gss_mech_config));
2N/A if (aMech == NULL) {
2N/A free(mechOid->elements);
2N/A free(mechOid);
2N/A continue;
2N/A }
2N/A (void) memset(aMech, 0, sizeof (struct gss_mech_config));
2N/A aMech->mech_type = mechOid;
2N/A aMech->uLibName = strdup(sharedPath);
2N/A aMech->mechNameStr = strdup(oidStr);
2N/A
2N/A /* check if any memory allocations failed - bad news */
2N/A if (aMech->uLibName == NULL || aMech->mechNameStr == NULL) {
2N/A if (aMech->uLibName)
2N/A free(aMech->uLibName);
2N/A if (aMech->mechNameStr)
2N/A free(aMech->mechNameStr);
2N/A free(mechOid->elements);
2N/A free(mechOid);
2N/A free(aMech);
2N/A continue;
2N/A }
2N/A if (kernMod) /* this is an optional parameter */
2N/A aMech->kmodName = strdup(kernMod);
2N/A
2N/A if (modOptions)
2N/A aMech->optionStr = strdup(modOptions);
2N/A /*
2N/A * add the new entry to the end of the list - make sure
2N/A * that only complete entries are added because other
2N/A * threads might currently be searching the list.
2N/A */
2N/A tmp = g_mechListTail;
2N/A g_mechListTail = aMech;
2N/A
2N/A if (tmp != NULL)
2N/A tmp->next = aMech;
2N/A
2N/A if (g_mechList == NULL)
2N/A g_mechList = aMech;
2N/A } /* while */
2N/A (void) fclose(confFile);
2N/A} /* loadConfigFile */