Oops! Remove junk...
[openssl.git] / crypto / dso / dso_lib.c
index 364ddbdb37179e7c22acb2f65bca7eeff7be4993..f4d148c24ad3a0030f966737c34cb887c0041d19 100644 (file)
@@ -1,4 +1,4 @@
-/* dso_lib.c */
+/* dso_lib.c -*- mode:C; c-file-style: "eay" -*- */
 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
  * project 2000.
  */
@@ -108,7 +108,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
                }
        memset(ret, 0, sizeof(DSO));
        ret->meth_data = sk_new_null();
-       if((ret->meth_data = sk_new_null()) == NULL)
+       if(ret->meth_data == NULL)
                {
                /* sk_new doesn't generate any errors so we do */
                DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -179,11 +179,11 @@ int DSO_flags(DSO *dso)
        }
 
 
-int DSO_up(DSO *dso)
+int DSO_up_ref(DSO *dso)
        {
        if (dso == NULL)
                {
-               DSOerr(DSO_F_DSO_UP,ERR_R_PASSED_NULL_PARAMETER);
+               DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
                return(0);
                }
 
@@ -205,6 +205,12 @@ DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
                        goto err;
                        }
                allocated = 1;
+               /* Pass the provided flags to the new DSO object */
+               if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
+                       {
+                       DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
+                       goto err;
+                       }
                }
        else
                ret = dso;
@@ -228,13 +234,6 @@ DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
                DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
                goto err;
                }
-       /* Bleurgh ... have to check for negative return values for
-        * errors. <grimace> */
-       if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
-               {
-               DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
-               goto err;
-               }
        if(ret->meth->dso_load == NULL)
                {
                DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
@@ -384,13 +383,40 @@ int DSO_set_filename(DSO *dso, const char *filename)
                DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
                return(0);
                }
-       strcpy(copied, filename);
+       BUF_strlcpy(copied, filename, strlen(filename) + 1);
        if(dso->filename)
                OPENSSL_free(dso->filename);
        dso->filename = copied;
        return(1);
        }
 
+char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
+       {
+       char *result = NULL;
+
+       if(dso == NULL || filespec1 == NULL)
+               {
+               DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
+               return(NULL);
+               }
+       if(filespec1 == NULL)
+               filespec1 = dso->filename;
+       if(filespec1 == NULL)
+               {
+               DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
+               return(NULL);
+               }
+       if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
+               {
+               if(dso->merger != NULL)
+                       result = dso->merger(dso, filespec1, filespec2);
+               else if(dso->meth->dso_merger != NULL)
+                       result = dso->meth->dso_merger(dso,
+                               filespec1, filespec2);
+               }
+       return(result);
+       }
+
 char *DSO_convert_filename(DSO *dso, const char *filename)
        {
        char *result = NULL;
@@ -423,7 +449,7 @@ char *DSO_convert_filename(DSO *dso, const char *filename)
                                        ERR_R_MALLOC_FAILURE);
                        return(NULL);
                        }
-               strcpy(result, filename);
+               BUF_strlcpy(result, filename, strlen(filename) + 1);
                }
        return(result);
        }
@@ -438,3 +464,35 @@ const char *DSO_get_loaded_filename(DSO *dso)
                }
        return(dso->loaded_filename);
        }
+
+int DSO_pathbyaddr(void *addr,char *path,int sz)
+       {
+       DSO_METHOD *meth = default_DSO_meth;
+       if (meth == NULL) meth = DSO_METHOD_openssl();
+       if (meth->pathbyaddr == NULL)
+               {
+               DSOerr(DSO_F_PATHBYADDR,DSO_R_UNSUPPORTED);
+               return -1;
+               }
+       return (*meth->pathbyaddr)(addr,path,sz);
+       }
+
+/* This function should be used with caution! It looks up symbols in
+ * *all* loaded modules and if module gets unloaded by somebody else
+ * attempt to dereference the pointer is doomed to have fatal
+ * consequences. Primary usage for this function is to probe *core*
+ * system functionality, e.g. check if getnameinfo(3) is available
+ * at run-time without bothering about OS-specific details such as
+ * libc.so.versioning or where does it actually reside: in libc
+ * itself or libsocket. */
+DSO_FUNC_TYPE DSO_global_lookup_func(const char *name)
+       {
+       DSO_METHOD *meth = default_DSO_meth;
+       if (meth == NULL) meth = DSO_METHOD_openssl();
+       if (meth->globallookup == NULL)
+               {
+               DSOerr(DSO_F_GLOBAL_LOOKUP_FUNC,DSO_R_UNSUPPORTED);
+               return NULL;
+               }
+       return (*meth->globallookup)(name);
+       }