1*0Sstevel@tonic-gate /* dso_lib.c */ 2*0Sstevel@tonic-gate /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 3*0Sstevel@tonic-gate * project 2000. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate /* ==================================================================== 6*0Sstevel@tonic-gate * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 7*0Sstevel@tonic-gate * 8*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 9*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 10*0Sstevel@tonic-gate * are met: 11*0Sstevel@tonic-gate * 12*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 13*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 14*0Sstevel@tonic-gate * 15*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 16*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 17*0Sstevel@tonic-gate * the documentation and/or other materials provided with the 18*0Sstevel@tonic-gate * distribution. 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this 21*0Sstevel@tonic-gate * software must display the following acknowledgment: 22*0Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 23*0Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24*0Sstevel@tonic-gate * 25*0Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26*0Sstevel@tonic-gate * endorse or promote products derived from this software without 27*0Sstevel@tonic-gate * prior written permission. For written permission, please contact 28*0Sstevel@tonic-gate * licensing@OpenSSL.org. 29*0Sstevel@tonic-gate * 30*0Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL" 31*0Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written 32*0Sstevel@tonic-gate * permission of the OpenSSL Project. 33*0Sstevel@tonic-gate * 34*0Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following 35*0Sstevel@tonic-gate * acknowledgment: 36*0Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 37*0Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38*0Sstevel@tonic-gate * 39*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40*0Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41*0Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42*0Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43*0Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44*0Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46*0Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47*0Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48*0Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49*0Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50*0Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE. 51*0Sstevel@tonic-gate * ==================================================================== 52*0Sstevel@tonic-gate * 53*0Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young 54*0Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim 55*0Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com). 56*0Sstevel@tonic-gate * 57*0Sstevel@tonic-gate */ 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate #include <stdio.h> 60*0Sstevel@tonic-gate #include <openssl/crypto.h> 61*0Sstevel@tonic-gate #include "cryptlib.h" 62*0Sstevel@tonic-gate #include <openssl/dso.h> 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate static DSO_METHOD *default_DSO_meth = NULL; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate DSO *DSO_new(void) 67*0Sstevel@tonic-gate { 68*0Sstevel@tonic-gate return(DSO_new_method(NULL)); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate void DSO_set_default_method(DSO_METHOD *meth) 72*0Sstevel@tonic-gate { 73*0Sstevel@tonic-gate default_DSO_meth = meth; 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate DSO_METHOD *DSO_get_default_method(void) 77*0Sstevel@tonic-gate { 78*0Sstevel@tonic-gate return(default_DSO_meth); 79*0Sstevel@tonic-gate } 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate DSO_METHOD *DSO_get_method(DSO *dso) 82*0Sstevel@tonic-gate { 83*0Sstevel@tonic-gate return(dso->meth); 84*0Sstevel@tonic-gate } 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth) 87*0Sstevel@tonic-gate { 88*0Sstevel@tonic-gate DSO_METHOD *mtmp; 89*0Sstevel@tonic-gate mtmp = dso->meth; 90*0Sstevel@tonic-gate dso->meth = meth; 91*0Sstevel@tonic-gate return(mtmp); 92*0Sstevel@tonic-gate } 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate DSO *DSO_new_method(DSO_METHOD *meth) 95*0Sstevel@tonic-gate { 96*0Sstevel@tonic-gate DSO *ret; 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate if(default_DSO_meth == NULL) 99*0Sstevel@tonic-gate /* We default to DSO_METH_openssl() which in turn defaults 100*0Sstevel@tonic-gate * to stealing the "best available" method. Will fallback 101*0Sstevel@tonic-gate * to DSO_METH_null() in the worst case. */ 102*0Sstevel@tonic-gate default_DSO_meth = DSO_METHOD_openssl(); 103*0Sstevel@tonic-gate ret = (DSO *)OPENSSL_malloc(sizeof(DSO)); 104*0Sstevel@tonic-gate if(ret == NULL) 105*0Sstevel@tonic-gate { 106*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); 107*0Sstevel@tonic-gate return(NULL); 108*0Sstevel@tonic-gate } 109*0Sstevel@tonic-gate memset(ret, 0, sizeof(DSO)); 110*0Sstevel@tonic-gate ret->meth_data = sk_new_null(); 111*0Sstevel@tonic-gate if(ret->meth_data == NULL) 112*0Sstevel@tonic-gate { 113*0Sstevel@tonic-gate /* sk_new doesn't generate any errors so we do */ 114*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); 115*0Sstevel@tonic-gate OPENSSL_free(ret); 116*0Sstevel@tonic-gate return(NULL); 117*0Sstevel@tonic-gate } 118*0Sstevel@tonic-gate if(meth == NULL) 119*0Sstevel@tonic-gate ret->meth = default_DSO_meth; 120*0Sstevel@tonic-gate else 121*0Sstevel@tonic-gate ret->meth = meth; 122*0Sstevel@tonic-gate ret->references = 1; 123*0Sstevel@tonic-gate if((ret->meth->init != NULL) && !ret->meth->init(ret)) 124*0Sstevel@tonic-gate { 125*0Sstevel@tonic-gate OPENSSL_free(ret); 126*0Sstevel@tonic-gate ret=NULL; 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate return(ret); 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate int DSO_free(DSO *dso) 132*0Sstevel@tonic-gate { 133*0Sstevel@tonic-gate int i; 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate if(dso == NULL) 136*0Sstevel@tonic-gate { 137*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER); 138*0Sstevel@tonic-gate return(0); 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO); 142*0Sstevel@tonic-gate #ifdef REF_PRINT 143*0Sstevel@tonic-gate REF_PRINT("DSO",dso); 144*0Sstevel@tonic-gate #endif 145*0Sstevel@tonic-gate if(i > 0) return(1); 146*0Sstevel@tonic-gate #ifdef REF_CHECK 147*0Sstevel@tonic-gate if(i < 0) 148*0Sstevel@tonic-gate { 149*0Sstevel@tonic-gate fprintf(stderr,"DSO_free, bad reference count\n"); 150*0Sstevel@tonic-gate abort(); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate #endif 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) 155*0Sstevel@tonic-gate { 156*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED); 157*0Sstevel@tonic-gate return(0); 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate if((dso->meth->finish != NULL) && !dso->meth->finish(dso)) 161*0Sstevel@tonic-gate { 162*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED); 163*0Sstevel@tonic-gate return(0); 164*0Sstevel@tonic-gate } 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate sk_free(dso->meth_data); 167*0Sstevel@tonic-gate if(dso->filename != NULL) 168*0Sstevel@tonic-gate OPENSSL_free(dso->filename); 169*0Sstevel@tonic-gate if(dso->loaded_filename != NULL) 170*0Sstevel@tonic-gate OPENSSL_free(dso->loaded_filename); 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate OPENSSL_free(dso); 173*0Sstevel@tonic-gate return(1); 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate int DSO_flags(DSO *dso) 177*0Sstevel@tonic-gate { 178*0Sstevel@tonic-gate return((dso == NULL) ? 0 : dso->flags); 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate int DSO_up_ref(DSO *dso) 183*0Sstevel@tonic-gate { 184*0Sstevel@tonic-gate if (dso == NULL) 185*0Sstevel@tonic-gate { 186*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER); 187*0Sstevel@tonic-gate return(0); 188*0Sstevel@tonic-gate } 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO); 191*0Sstevel@tonic-gate return(1); 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) 195*0Sstevel@tonic-gate { 196*0Sstevel@tonic-gate DSO *ret; 197*0Sstevel@tonic-gate int allocated = 0; 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate if(dso == NULL) 200*0Sstevel@tonic-gate { 201*0Sstevel@tonic-gate ret = DSO_new_method(meth); 202*0Sstevel@tonic-gate if(ret == NULL) 203*0Sstevel@tonic-gate { 204*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); 205*0Sstevel@tonic-gate goto err; 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate allocated = 1; 208*0Sstevel@tonic-gate /* Pass the provided flags to the new DSO object */ 209*0Sstevel@tonic-gate if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) 210*0Sstevel@tonic-gate { 211*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); 212*0Sstevel@tonic-gate goto err; 213*0Sstevel@tonic-gate } 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate else 216*0Sstevel@tonic-gate ret = dso; 217*0Sstevel@tonic-gate /* Don't load if we're currently already loaded */ 218*0Sstevel@tonic-gate if(ret->filename != NULL) 219*0Sstevel@tonic-gate { 220*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED); 221*0Sstevel@tonic-gate goto err; 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate /* filename can only be NULL if we were passed a dso that already has 224*0Sstevel@tonic-gate * one set. */ 225*0Sstevel@tonic-gate if(filename != NULL) 226*0Sstevel@tonic-gate if(!DSO_set_filename(ret, filename)) 227*0Sstevel@tonic-gate { 228*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED); 229*0Sstevel@tonic-gate goto err; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate filename = ret->filename; 232*0Sstevel@tonic-gate if(filename == NULL) 233*0Sstevel@tonic-gate { 234*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME); 235*0Sstevel@tonic-gate goto err; 236*0Sstevel@tonic-gate } 237*0Sstevel@tonic-gate if(ret->meth->dso_load == NULL) 238*0Sstevel@tonic-gate { 239*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); 240*0Sstevel@tonic-gate goto err; 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate if(!ret->meth->dso_load(ret)) 243*0Sstevel@tonic-gate { 244*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); 245*0Sstevel@tonic-gate goto err; 246*0Sstevel@tonic-gate } 247*0Sstevel@tonic-gate /* Load succeeded */ 248*0Sstevel@tonic-gate return(ret); 249*0Sstevel@tonic-gate err: 250*0Sstevel@tonic-gate if(allocated) 251*0Sstevel@tonic-gate DSO_free(ret); 252*0Sstevel@tonic-gate return(NULL); 253*0Sstevel@tonic-gate } 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate void *DSO_bind_var(DSO *dso, const char *symname) 256*0Sstevel@tonic-gate { 257*0Sstevel@tonic-gate void *ret = NULL; 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate if((dso == NULL) || (symname == NULL)) 260*0Sstevel@tonic-gate { 261*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); 262*0Sstevel@tonic-gate return(NULL); 263*0Sstevel@tonic-gate } 264*0Sstevel@tonic-gate if(dso->meth->dso_bind_var == NULL) 265*0Sstevel@tonic-gate { 266*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED); 267*0Sstevel@tonic-gate return(NULL); 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) 270*0Sstevel@tonic-gate { 271*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE); 272*0Sstevel@tonic-gate return(NULL); 273*0Sstevel@tonic-gate } 274*0Sstevel@tonic-gate /* Success */ 275*0Sstevel@tonic-gate return(ret); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname) 279*0Sstevel@tonic-gate { 280*0Sstevel@tonic-gate DSO_FUNC_TYPE ret = NULL; 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate if((dso == NULL) || (symname == NULL)) 283*0Sstevel@tonic-gate { 284*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); 285*0Sstevel@tonic-gate return(NULL); 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate if(dso->meth->dso_bind_func == NULL) 288*0Sstevel@tonic-gate { 289*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED); 290*0Sstevel@tonic-gate return(NULL); 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) 293*0Sstevel@tonic-gate { 294*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE); 295*0Sstevel@tonic-gate return(NULL); 296*0Sstevel@tonic-gate } 297*0Sstevel@tonic-gate /* Success */ 298*0Sstevel@tonic-gate return(ret); 299*0Sstevel@tonic-gate } 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate /* I don't really like these *_ctrl functions very much to be perfectly 302*0Sstevel@tonic-gate * honest. For one thing, I think I have to return a negative value for 303*0Sstevel@tonic-gate * any error because possible DSO_ctrl() commands may return values 304*0Sstevel@tonic-gate * such as "size"s that can legitimately be zero (making the standard 305*0Sstevel@tonic-gate * "if(DSO_cmd(...))" form that works almost everywhere else fail at 306*0Sstevel@tonic-gate * odd times. I'd prefer "output" values to be passed by reference and 307*0Sstevel@tonic-gate * the return value as success/failure like usual ... but we conform 308*0Sstevel@tonic-gate * when we must... :-) */ 309*0Sstevel@tonic-gate long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) 310*0Sstevel@tonic-gate { 311*0Sstevel@tonic-gate if(dso == NULL) 312*0Sstevel@tonic-gate { 313*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); 314*0Sstevel@tonic-gate return(-1); 315*0Sstevel@tonic-gate } 316*0Sstevel@tonic-gate /* We should intercept certain generic commands and only pass control 317*0Sstevel@tonic-gate * to the method-specific ctrl() function if it's something we don't 318*0Sstevel@tonic-gate * handle. */ 319*0Sstevel@tonic-gate switch(cmd) 320*0Sstevel@tonic-gate { 321*0Sstevel@tonic-gate case DSO_CTRL_GET_FLAGS: 322*0Sstevel@tonic-gate return dso->flags; 323*0Sstevel@tonic-gate case DSO_CTRL_SET_FLAGS: 324*0Sstevel@tonic-gate dso->flags = (int)larg; 325*0Sstevel@tonic-gate return(0); 326*0Sstevel@tonic-gate case DSO_CTRL_OR_FLAGS: 327*0Sstevel@tonic-gate dso->flags |= (int)larg; 328*0Sstevel@tonic-gate return(0); 329*0Sstevel@tonic-gate default: 330*0Sstevel@tonic-gate break; 331*0Sstevel@tonic-gate } 332*0Sstevel@tonic-gate if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) 333*0Sstevel@tonic-gate { 334*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); 335*0Sstevel@tonic-gate return(-1); 336*0Sstevel@tonic-gate } 337*0Sstevel@tonic-gate return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); 338*0Sstevel@tonic-gate } 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, 341*0Sstevel@tonic-gate DSO_NAME_CONVERTER_FUNC *oldcb) 342*0Sstevel@tonic-gate { 343*0Sstevel@tonic-gate if(dso == NULL) 344*0Sstevel@tonic-gate { 345*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, 346*0Sstevel@tonic-gate ERR_R_PASSED_NULL_PARAMETER); 347*0Sstevel@tonic-gate return(0); 348*0Sstevel@tonic-gate } 349*0Sstevel@tonic-gate if(oldcb) 350*0Sstevel@tonic-gate *oldcb = dso->name_converter; 351*0Sstevel@tonic-gate dso->name_converter = cb; 352*0Sstevel@tonic-gate return(1); 353*0Sstevel@tonic-gate } 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate const char *DSO_get_filename(DSO *dso) 356*0Sstevel@tonic-gate { 357*0Sstevel@tonic-gate if(dso == NULL) 358*0Sstevel@tonic-gate { 359*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); 360*0Sstevel@tonic-gate return(NULL); 361*0Sstevel@tonic-gate } 362*0Sstevel@tonic-gate return(dso->filename); 363*0Sstevel@tonic-gate } 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate int DSO_set_filename(DSO *dso, const char *filename) 366*0Sstevel@tonic-gate { 367*0Sstevel@tonic-gate char *copied; 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate if((dso == NULL) || (filename == NULL)) 370*0Sstevel@tonic-gate { 371*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); 372*0Sstevel@tonic-gate return(0); 373*0Sstevel@tonic-gate } 374*0Sstevel@tonic-gate if(dso->loaded_filename) 375*0Sstevel@tonic-gate { 376*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED); 377*0Sstevel@tonic-gate return(0); 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate /* We'll duplicate filename */ 380*0Sstevel@tonic-gate copied = OPENSSL_malloc(strlen(filename) + 1); 381*0Sstevel@tonic-gate if(copied == NULL) 382*0Sstevel@tonic-gate { 383*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE); 384*0Sstevel@tonic-gate return(0); 385*0Sstevel@tonic-gate } 386*0Sstevel@tonic-gate BUF_strlcpy(copied, filename, strlen(filename) + 1); 387*0Sstevel@tonic-gate if(dso->filename) 388*0Sstevel@tonic-gate OPENSSL_free(dso->filename); 389*0Sstevel@tonic-gate dso->filename = copied; 390*0Sstevel@tonic-gate return(1); 391*0Sstevel@tonic-gate } 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate char *DSO_convert_filename(DSO *dso, const char *filename) 394*0Sstevel@tonic-gate { 395*0Sstevel@tonic-gate char *result = NULL; 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate if(dso == NULL) 398*0Sstevel@tonic-gate { 399*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER); 400*0Sstevel@tonic-gate return(NULL); 401*0Sstevel@tonic-gate } 402*0Sstevel@tonic-gate if(filename == NULL) 403*0Sstevel@tonic-gate filename = dso->filename; 404*0Sstevel@tonic-gate if(filename == NULL) 405*0Sstevel@tonic-gate { 406*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME); 407*0Sstevel@tonic-gate return(NULL); 408*0Sstevel@tonic-gate } 409*0Sstevel@tonic-gate if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) 410*0Sstevel@tonic-gate { 411*0Sstevel@tonic-gate if(dso->name_converter != NULL) 412*0Sstevel@tonic-gate result = dso->name_converter(dso, filename); 413*0Sstevel@tonic-gate else if(dso->meth->dso_name_converter != NULL) 414*0Sstevel@tonic-gate result = dso->meth->dso_name_converter(dso, filename); 415*0Sstevel@tonic-gate } 416*0Sstevel@tonic-gate if(result == NULL) 417*0Sstevel@tonic-gate { 418*0Sstevel@tonic-gate result = OPENSSL_malloc(strlen(filename) + 1); 419*0Sstevel@tonic-gate if(result == NULL) 420*0Sstevel@tonic-gate { 421*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_CONVERT_FILENAME, 422*0Sstevel@tonic-gate ERR_R_MALLOC_FAILURE); 423*0Sstevel@tonic-gate return(NULL); 424*0Sstevel@tonic-gate } 425*0Sstevel@tonic-gate BUF_strlcpy(result, filename, strlen(filename) + 1); 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate return(result); 428*0Sstevel@tonic-gate } 429*0Sstevel@tonic-gate 430*0Sstevel@tonic-gate const char *DSO_get_loaded_filename(DSO *dso) 431*0Sstevel@tonic-gate { 432*0Sstevel@tonic-gate if(dso == NULL) 433*0Sstevel@tonic-gate { 434*0Sstevel@tonic-gate DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, 435*0Sstevel@tonic-gate ERR_R_PASSED_NULL_PARAMETER); 436*0Sstevel@tonic-gate return(NULL); 437*0Sstevel@tonic-gate } 438*0Sstevel@tonic-gate return(dso->loaded_filename); 439*0Sstevel@tonic-gate } 440