xref: /onnv-gate/usr/src/common/openssl/crypto/dso/dso_lib.c (revision 2139:6243c3338933)
1*2139Sjp161948 /* dso_lib.c -*- mode:C; c-file-style: "eay" -*- */
20Sstevel@tonic-gate /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
30Sstevel@tonic-gate  * project 2000.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate /* ====================================================================
60Sstevel@tonic-gate  * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
90Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
100Sstevel@tonic-gate  * are met:
110Sstevel@tonic-gate  *
120Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate  *
150Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in
170Sstevel@tonic-gate  *    the documentation and/or other materials provided with the
180Sstevel@tonic-gate  *    distribution.
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this
210Sstevel@tonic-gate  *    software must display the following acknowledgment:
220Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
230Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
260Sstevel@tonic-gate  *    endorse or promote products derived from this software without
270Sstevel@tonic-gate  *    prior written permission. For written permission, please contact
280Sstevel@tonic-gate  *    licensing@OpenSSL.org.
290Sstevel@tonic-gate  *
300Sstevel@tonic-gate  * 5. Products derived from this software may not be called "OpenSSL"
310Sstevel@tonic-gate  *    nor may "OpenSSL" appear in their names without prior written
320Sstevel@tonic-gate  *    permission of the OpenSSL Project.
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * 6. Redistributions of any form whatsoever must retain the following
350Sstevel@tonic-gate  *    acknowledgment:
360Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
370Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
380Sstevel@tonic-gate  *
390Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
400Sstevel@tonic-gate  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
410Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
420Sstevel@tonic-gate  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
430Sstevel@tonic-gate  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
440Sstevel@tonic-gate  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
450Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
460Sstevel@tonic-gate  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
470Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
480Sstevel@tonic-gate  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
490Sstevel@tonic-gate  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
500Sstevel@tonic-gate  * OF THE POSSIBILITY OF SUCH DAMAGE.
510Sstevel@tonic-gate  * ====================================================================
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * This product includes cryptographic software written by Eric Young
540Sstevel@tonic-gate  * (eay@cryptsoft.com).  This product includes software written by Tim
550Sstevel@tonic-gate  * Hudson (tjh@cryptsoft.com).
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #include <stdio.h>
600Sstevel@tonic-gate #include <openssl/crypto.h>
610Sstevel@tonic-gate #include "cryptlib.h"
620Sstevel@tonic-gate #include <openssl/dso.h>
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static DSO_METHOD *default_DSO_meth = NULL;
650Sstevel@tonic-gate 
DSO_new(void)660Sstevel@tonic-gate DSO *DSO_new(void)
670Sstevel@tonic-gate 	{
680Sstevel@tonic-gate 	return(DSO_new_method(NULL));
690Sstevel@tonic-gate 	}
700Sstevel@tonic-gate 
DSO_set_default_method(DSO_METHOD * meth)710Sstevel@tonic-gate void DSO_set_default_method(DSO_METHOD *meth)
720Sstevel@tonic-gate 	{
730Sstevel@tonic-gate 	default_DSO_meth = meth;
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate 
DSO_get_default_method(void)760Sstevel@tonic-gate DSO_METHOD *DSO_get_default_method(void)
770Sstevel@tonic-gate 	{
780Sstevel@tonic-gate 	return(default_DSO_meth);
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate 
DSO_get_method(DSO * dso)810Sstevel@tonic-gate DSO_METHOD *DSO_get_method(DSO *dso)
820Sstevel@tonic-gate 	{
830Sstevel@tonic-gate 	return(dso->meth);
840Sstevel@tonic-gate 	}
850Sstevel@tonic-gate 
DSO_set_method(DSO * dso,DSO_METHOD * meth)860Sstevel@tonic-gate DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth)
870Sstevel@tonic-gate 	{
880Sstevel@tonic-gate 	DSO_METHOD *mtmp;
890Sstevel@tonic-gate 	mtmp = dso->meth;
900Sstevel@tonic-gate 	dso->meth = meth;
910Sstevel@tonic-gate 	return(mtmp);
920Sstevel@tonic-gate 	}
930Sstevel@tonic-gate 
DSO_new_method(DSO_METHOD * meth)940Sstevel@tonic-gate DSO *DSO_new_method(DSO_METHOD *meth)
950Sstevel@tonic-gate 	{
960Sstevel@tonic-gate 	DSO *ret;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	if(default_DSO_meth == NULL)
990Sstevel@tonic-gate 		/* We default to DSO_METH_openssl() which in turn defaults
1000Sstevel@tonic-gate 		 * to stealing the "best available" method. Will fallback
1010Sstevel@tonic-gate 		 * to DSO_METH_null() in the worst case. */
1020Sstevel@tonic-gate 		default_DSO_meth = DSO_METHOD_openssl();
1030Sstevel@tonic-gate 	ret = (DSO *)OPENSSL_malloc(sizeof(DSO));
1040Sstevel@tonic-gate 	if(ret == NULL)
1050Sstevel@tonic-gate 		{
1060Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
1070Sstevel@tonic-gate 		return(NULL);
1080Sstevel@tonic-gate 		}
1090Sstevel@tonic-gate 	memset(ret, 0, sizeof(DSO));
1100Sstevel@tonic-gate 	ret->meth_data = sk_new_null();
1110Sstevel@tonic-gate 	if(ret->meth_data == NULL)
1120Sstevel@tonic-gate 		{
1130Sstevel@tonic-gate 		/* sk_new doesn't generate any errors so we do */
1140Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
1150Sstevel@tonic-gate 		OPENSSL_free(ret);
1160Sstevel@tonic-gate 		return(NULL);
1170Sstevel@tonic-gate 		}
1180Sstevel@tonic-gate 	if(meth == NULL)
1190Sstevel@tonic-gate 		ret->meth = default_DSO_meth;
1200Sstevel@tonic-gate 	else
1210Sstevel@tonic-gate 		ret->meth = meth;
1220Sstevel@tonic-gate 	ret->references = 1;
1230Sstevel@tonic-gate 	if((ret->meth->init != NULL) && !ret->meth->init(ret))
1240Sstevel@tonic-gate 		{
1250Sstevel@tonic-gate 		OPENSSL_free(ret);
1260Sstevel@tonic-gate 		ret=NULL;
1270Sstevel@tonic-gate 		}
1280Sstevel@tonic-gate 	return(ret);
1290Sstevel@tonic-gate 	}
1300Sstevel@tonic-gate 
DSO_free(DSO * dso)1310Sstevel@tonic-gate int DSO_free(DSO *dso)
1320Sstevel@tonic-gate 	{
1330Sstevel@tonic-gate         int i;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	if(dso == NULL)
1360Sstevel@tonic-gate 		{
1370Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER);
1380Sstevel@tonic-gate 		return(0);
1390Sstevel@tonic-gate 		}
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO);
1420Sstevel@tonic-gate #ifdef REF_PRINT
1430Sstevel@tonic-gate 	REF_PRINT("DSO",dso);
1440Sstevel@tonic-gate #endif
1450Sstevel@tonic-gate 	if(i > 0) return(1);
1460Sstevel@tonic-gate #ifdef REF_CHECK
1470Sstevel@tonic-gate 	if(i < 0)
1480Sstevel@tonic-gate 		{
1490Sstevel@tonic-gate 		fprintf(stderr,"DSO_free, bad reference count\n");
1500Sstevel@tonic-gate 		abort();
1510Sstevel@tonic-gate 		}
1520Sstevel@tonic-gate #endif
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso))
1550Sstevel@tonic-gate 		{
1560Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED);
1570Sstevel@tonic-gate 		return(0);
1580Sstevel@tonic-gate 		}
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	if((dso->meth->finish != NULL) && !dso->meth->finish(dso))
1610Sstevel@tonic-gate 		{
1620Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED);
1630Sstevel@tonic-gate 		return(0);
1640Sstevel@tonic-gate 		}
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	sk_free(dso->meth_data);
1670Sstevel@tonic-gate 	if(dso->filename != NULL)
1680Sstevel@tonic-gate 		OPENSSL_free(dso->filename);
1690Sstevel@tonic-gate 	if(dso->loaded_filename != NULL)
1700Sstevel@tonic-gate 		OPENSSL_free(dso->loaded_filename);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	OPENSSL_free(dso);
1730Sstevel@tonic-gate 	return(1);
1740Sstevel@tonic-gate 	}
1750Sstevel@tonic-gate 
DSO_flags(DSO * dso)1760Sstevel@tonic-gate int DSO_flags(DSO *dso)
1770Sstevel@tonic-gate 	{
1780Sstevel@tonic-gate 	return((dso == NULL) ? 0 : dso->flags);
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 
DSO_up_ref(DSO * dso)1820Sstevel@tonic-gate int DSO_up_ref(DSO *dso)
1830Sstevel@tonic-gate 	{
1840Sstevel@tonic-gate 	if (dso == NULL)
1850Sstevel@tonic-gate 		{
1860Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
1870Sstevel@tonic-gate 		return(0);
1880Sstevel@tonic-gate 		}
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO);
1910Sstevel@tonic-gate 	return(1);
1920Sstevel@tonic-gate 	}
1930Sstevel@tonic-gate 
DSO_load(DSO * dso,const char * filename,DSO_METHOD * meth,int flags)1940Sstevel@tonic-gate DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
1950Sstevel@tonic-gate 	{
1960Sstevel@tonic-gate 	DSO *ret;
1970Sstevel@tonic-gate 	int allocated = 0;
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	if(dso == NULL)
2000Sstevel@tonic-gate 		{
2010Sstevel@tonic-gate 		ret = DSO_new_method(meth);
2020Sstevel@tonic-gate 		if(ret == NULL)
2030Sstevel@tonic-gate 			{
2040Sstevel@tonic-gate 			DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
2050Sstevel@tonic-gate 			goto err;
2060Sstevel@tonic-gate 			}
2070Sstevel@tonic-gate 		allocated = 1;
2080Sstevel@tonic-gate 		/* Pass the provided flags to the new DSO object */
2090Sstevel@tonic-gate 		if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
2100Sstevel@tonic-gate 			{
2110Sstevel@tonic-gate 			DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
2120Sstevel@tonic-gate 			goto err;
2130Sstevel@tonic-gate 			}
2140Sstevel@tonic-gate 		}
2150Sstevel@tonic-gate 	else
2160Sstevel@tonic-gate 		ret = dso;
2170Sstevel@tonic-gate 	/* Don't load if we're currently already loaded */
2180Sstevel@tonic-gate 	if(ret->filename != NULL)
2190Sstevel@tonic-gate 		{
2200Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED);
2210Sstevel@tonic-gate 		goto err;
2220Sstevel@tonic-gate 		}
2230Sstevel@tonic-gate 	/* filename can only be NULL if we were passed a dso that already has
2240Sstevel@tonic-gate 	 * one set. */
2250Sstevel@tonic-gate 	if(filename != NULL)
2260Sstevel@tonic-gate 		if(!DSO_set_filename(ret, filename))
2270Sstevel@tonic-gate 			{
2280Sstevel@tonic-gate 			DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED);
2290Sstevel@tonic-gate 			goto err;
2300Sstevel@tonic-gate 			}
2310Sstevel@tonic-gate 	filename = ret->filename;
2320Sstevel@tonic-gate 	if(filename == NULL)
2330Sstevel@tonic-gate 		{
2340Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
2350Sstevel@tonic-gate 		goto err;
2360Sstevel@tonic-gate 		}
2370Sstevel@tonic-gate 	if(ret->meth->dso_load == NULL)
2380Sstevel@tonic-gate 		{
2390Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
2400Sstevel@tonic-gate 		goto err;
2410Sstevel@tonic-gate 		}
2420Sstevel@tonic-gate 	if(!ret->meth->dso_load(ret))
2430Sstevel@tonic-gate 		{
2440Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
2450Sstevel@tonic-gate 		goto err;
2460Sstevel@tonic-gate 		}
2470Sstevel@tonic-gate 	/* Load succeeded */
2480Sstevel@tonic-gate 	return(ret);
2490Sstevel@tonic-gate err:
2500Sstevel@tonic-gate 	if(allocated)
2510Sstevel@tonic-gate 		DSO_free(ret);
2520Sstevel@tonic-gate 	return(NULL);
2530Sstevel@tonic-gate 	}
2540Sstevel@tonic-gate 
DSO_bind_var(DSO * dso,const char * symname)2550Sstevel@tonic-gate void *DSO_bind_var(DSO *dso, const char *symname)
2560Sstevel@tonic-gate 	{
2570Sstevel@tonic-gate 	void *ret = NULL;
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 	if((dso == NULL) || (symname == NULL))
2600Sstevel@tonic-gate 		{
2610Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
2620Sstevel@tonic-gate 		return(NULL);
2630Sstevel@tonic-gate 		}
2640Sstevel@tonic-gate 	if(dso->meth->dso_bind_var == NULL)
2650Sstevel@tonic-gate 		{
2660Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED);
2670Sstevel@tonic-gate 		return(NULL);
2680Sstevel@tonic-gate 		}
2690Sstevel@tonic-gate 	if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL)
2700Sstevel@tonic-gate 		{
2710Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE);
2720Sstevel@tonic-gate 		return(NULL);
2730Sstevel@tonic-gate 		}
2740Sstevel@tonic-gate 	/* Success */
2750Sstevel@tonic-gate 	return(ret);
2760Sstevel@tonic-gate 	}
2770Sstevel@tonic-gate 
DSO_bind_func(DSO * dso,const char * symname)2780Sstevel@tonic-gate DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
2790Sstevel@tonic-gate 	{
2800Sstevel@tonic-gate 	DSO_FUNC_TYPE ret = NULL;
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate 	if((dso == NULL) || (symname == NULL))
2830Sstevel@tonic-gate 		{
2840Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
2850Sstevel@tonic-gate 		return(NULL);
2860Sstevel@tonic-gate 		}
2870Sstevel@tonic-gate 	if(dso->meth->dso_bind_func == NULL)
2880Sstevel@tonic-gate 		{
2890Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED);
2900Sstevel@tonic-gate 		return(NULL);
2910Sstevel@tonic-gate 		}
2920Sstevel@tonic-gate 	if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL)
2930Sstevel@tonic-gate 		{
2940Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE);
2950Sstevel@tonic-gate 		return(NULL);
2960Sstevel@tonic-gate 		}
2970Sstevel@tonic-gate 	/* Success */
2980Sstevel@tonic-gate 	return(ret);
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate /* I don't really like these *_ctrl functions very much to be perfectly
3020Sstevel@tonic-gate  * honest. For one thing, I think I have to return a negative value for
3030Sstevel@tonic-gate  * any error because possible DSO_ctrl() commands may return values
3040Sstevel@tonic-gate  * such as "size"s that can legitimately be zero (making the standard
3050Sstevel@tonic-gate  * "if(DSO_cmd(...))" form that works almost everywhere else fail at
3060Sstevel@tonic-gate  * odd times. I'd prefer "output" values to be passed by reference and
3070Sstevel@tonic-gate  * the return value as success/failure like usual ... but we conform
3080Sstevel@tonic-gate  * when we must... :-) */
DSO_ctrl(DSO * dso,int cmd,long larg,void * parg)3090Sstevel@tonic-gate long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
3100Sstevel@tonic-gate 	{
3110Sstevel@tonic-gate 	if(dso == NULL)
3120Sstevel@tonic-gate 		{
3130Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
3140Sstevel@tonic-gate 		return(-1);
3150Sstevel@tonic-gate 		}
3160Sstevel@tonic-gate 	/* We should intercept certain generic commands and only pass control
3170Sstevel@tonic-gate 	 * to the method-specific ctrl() function if it's something we don't
3180Sstevel@tonic-gate 	 * handle. */
3190Sstevel@tonic-gate 	switch(cmd)
3200Sstevel@tonic-gate 		{
3210Sstevel@tonic-gate 	case DSO_CTRL_GET_FLAGS:
3220Sstevel@tonic-gate 		return dso->flags;
3230Sstevel@tonic-gate 	case DSO_CTRL_SET_FLAGS:
3240Sstevel@tonic-gate 		dso->flags = (int)larg;
3250Sstevel@tonic-gate 		return(0);
3260Sstevel@tonic-gate 	case DSO_CTRL_OR_FLAGS:
3270Sstevel@tonic-gate 		dso->flags |= (int)larg;
3280Sstevel@tonic-gate 		return(0);
3290Sstevel@tonic-gate 	default:
3300Sstevel@tonic-gate 		break;
3310Sstevel@tonic-gate 		}
3320Sstevel@tonic-gate 	if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
3330Sstevel@tonic-gate 		{
3340Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
3350Sstevel@tonic-gate 		return(-1);
3360Sstevel@tonic-gate 		}
3370Sstevel@tonic-gate 	return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
3380Sstevel@tonic-gate 	}
3390Sstevel@tonic-gate 
DSO_set_name_converter(DSO * dso,DSO_NAME_CONVERTER_FUNC cb,DSO_NAME_CONVERTER_FUNC * oldcb)3400Sstevel@tonic-gate int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
3410Sstevel@tonic-gate 			DSO_NAME_CONVERTER_FUNC *oldcb)
3420Sstevel@tonic-gate 	{
3430Sstevel@tonic-gate 	if(dso == NULL)
3440Sstevel@tonic-gate 		{
3450Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_SET_NAME_CONVERTER,
3460Sstevel@tonic-gate 				ERR_R_PASSED_NULL_PARAMETER);
3470Sstevel@tonic-gate 		return(0);
3480Sstevel@tonic-gate 		}
3490Sstevel@tonic-gate 	if(oldcb)
3500Sstevel@tonic-gate 		*oldcb = dso->name_converter;
3510Sstevel@tonic-gate 	dso->name_converter = cb;
3520Sstevel@tonic-gate 	return(1);
3530Sstevel@tonic-gate 	}
3540Sstevel@tonic-gate 
DSO_get_filename(DSO * dso)3550Sstevel@tonic-gate const char *DSO_get_filename(DSO *dso)
3560Sstevel@tonic-gate 	{
3570Sstevel@tonic-gate 	if(dso == NULL)
3580Sstevel@tonic-gate 		{
3590Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
3600Sstevel@tonic-gate 		return(NULL);
3610Sstevel@tonic-gate 		}
3620Sstevel@tonic-gate 	return(dso->filename);
3630Sstevel@tonic-gate 	}
3640Sstevel@tonic-gate 
DSO_set_filename(DSO * dso,const char * filename)3650Sstevel@tonic-gate int DSO_set_filename(DSO *dso, const char *filename)
3660Sstevel@tonic-gate 	{
3670Sstevel@tonic-gate 	char *copied;
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 	if((dso == NULL) || (filename == NULL))
3700Sstevel@tonic-gate 		{
3710Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
3720Sstevel@tonic-gate 		return(0);
3730Sstevel@tonic-gate 		}
3740Sstevel@tonic-gate 	if(dso->loaded_filename)
3750Sstevel@tonic-gate 		{
3760Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED);
3770Sstevel@tonic-gate 		return(0);
3780Sstevel@tonic-gate 		}
3790Sstevel@tonic-gate 	/* We'll duplicate filename */
3800Sstevel@tonic-gate 	copied = OPENSSL_malloc(strlen(filename) + 1);
3810Sstevel@tonic-gate 	if(copied == NULL)
3820Sstevel@tonic-gate 		{
3830Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
3840Sstevel@tonic-gate 		return(0);
3850Sstevel@tonic-gate 		}
3860Sstevel@tonic-gate 	BUF_strlcpy(copied, filename, strlen(filename) + 1);
3870Sstevel@tonic-gate 	if(dso->filename)
3880Sstevel@tonic-gate 		OPENSSL_free(dso->filename);
3890Sstevel@tonic-gate 	dso->filename = copied;
3900Sstevel@tonic-gate 	return(1);
3910Sstevel@tonic-gate 	}
3920Sstevel@tonic-gate 
DSO_merge(DSO * dso,const char * filespec1,const char * filespec2)393*2139Sjp161948 char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
394*2139Sjp161948 	{
395*2139Sjp161948 	char *result = NULL;
396*2139Sjp161948 
397*2139Sjp161948 	if(dso == NULL || filespec1 == NULL)
398*2139Sjp161948 		{
399*2139Sjp161948 		DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
400*2139Sjp161948 		return(NULL);
401*2139Sjp161948 		}
402*2139Sjp161948 	if(filespec1 == NULL)
403*2139Sjp161948 		filespec1 = dso->filename;
404*2139Sjp161948 	if(filespec1 == NULL)
405*2139Sjp161948 		{
406*2139Sjp161948 		DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
407*2139Sjp161948 		return(NULL);
408*2139Sjp161948 		}
409*2139Sjp161948 	if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
410*2139Sjp161948 		{
411*2139Sjp161948 		if(dso->merger != NULL)
412*2139Sjp161948 			result = dso->merger(dso, filespec1, filespec2);
413*2139Sjp161948 		else if(dso->meth->dso_merger != NULL)
414*2139Sjp161948 			result = dso->meth->dso_merger(dso,
415*2139Sjp161948 				filespec1, filespec2);
416*2139Sjp161948 		}
417*2139Sjp161948 	return(result);
418*2139Sjp161948 	}
419*2139Sjp161948 
DSO_convert_filename(DSO * dso,const char * filename)4200Sstevel@tonic-gate char *DSO_convert_filename(DSO *dso, const char *filename)
4210Sstevel@tonic-gate 	{
4220Sstevel@tonic-gate 	char *result = NULL;
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 	if(dso == NULL)
4250Sstevel@tonic-gate 		{
4260Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
4270Sstevel@tonic-gate 		return(NULL);
4280Sstevel@tonic-gate 		}
4290Sstevel@tonic-gate 	if(filename == NULL)
4300Sstevel@tonic-gate 		filename = dso->filename;
4310Sstevel@tonic-gate 	if(filename == NULL)
4320Sstevel@tonic-gate 		{
4330Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME);
4340Sstevel@tonic-gate 		return(NULL);
4350Sstevel@tonic-gate 		}
4360Sstevel@tonic-gate 	if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
4370Sstevel@tonic-gate 		{
4380Sstevel@tonic-gate 		if(dso->name_converter != NULL)
4390Sstevel@tonic-gate 			result = dso->name_converter(dso, filename);
4400Sstevel@tonic-gate 		else if(dso->meth->dso_name_converter != NULL)
4410Sstevel@tonic-gate 			result = dso->meth->dso_name_converter(dso, filename);
4420Sstevel@tonic-gate 		}
4430Sstevel@tonic-gate 	if(result == NULL)
4440Sstevel@tonic-gate 		{
4450Sstevel@tonic-gate 		result = OPENSSL_malloc(strlen(filename) + 1);
4460Sstevel@tonic-gate 		if(result == NULL)
4470Sstevel@tonic-gate 			{
4480Sstevel@tonic-gate 			DSOerr(DSO_F_DSO_CONVERT_FILENAME,
4490Sstevel@tonic-gate 					ERR_R_MALLOC_FAILURE);
4500Sstevel@tonic-gate 			return(NULL);
4510Sstevel@tonic-gate 			}
4520Sstevel@tonic-gate 		BUF_strlcpy(result, filename, strlen(filename) + 1);
4530Sstevel@tonic-gate 		}
4540Sstevel@tonic-gate 	return(result);
4550Sstevel@tonic-gate 	}
4560Sstevel@tonic-gate 
DSO_get_loaded_filename(DSO * dso)4570Sstevel@tonic-gate const char *DSO_get_loaded_filename(DSO *dso)
4580Sstevel@tonic-gate 	{
4590Sstevel@tonic-gate 	if(dso == NULL)
4600Sstevel@tonic-gate 		{
4610Sstevel@tonic-gate 		DSOerr(DSO_F_DSO_GET_LOADED_FILENAME,
4620Sstevel@tonic-gate 				ERR_R_PASSED_NULL_PARAMETER);
4630Sstevel@tonic-gate 		return(NULL);
4640Sstevel@tonic-gate 		}
4650Sstevel@tonic-gate 	return(dso->loaded_filename);
4660Sstevel@tonic-gate 	}
467