From f1625f274acf5dcd5601f6cb5e29e233b2a441a3 Mon Sep 17 00:00:00 2001 From: djm <> Date: Sat, 6 Sep 2008 12:15:54 +0000 Subject: import of OpenSSL 0.9.8h --- src/lib/libcrypto/dso/Makefile | 46 ++--- src/lib/libcrypto/dso/dso_dl.c | 102 +++++++---- src/lib/libcrypto/dso/dso_vms.c | 137 +++++++++++++- src/lib/libcrypto/dso/dso_win32.c | 364 +++++++++++++++++++++++++++++++++++++- 4 files changed, 587 insertions(+), 62 deletions(-) (limited to 'src/lib/libcrypto/dso') diff --git a/src/lib/libcrypto/dso/Makefile b/src/lib/libcrypto/dso/Makefile index c16278c3ff..07f5d8d159 100644 --- a/src/lib/libcrypto/dso/Makefile +++ b/src/lib/libcrypto/dso/Makefile @@ -7,11 +7,6 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I$(TOP) -I../../include CFLAG=-g -INSTALL_PREFIX= -OPENSSLDIR= /usr/local/ssl -INSTALLTOP=/usr/local/ssl -MAKEDEPPROG= makedepend -MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) MAKEFILE= Makefile AR= ar r @@ -53,6 +48,7 @@ links: @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: + @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ do \ (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ @@ -68,6 +64,7 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: + @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) dclean: @@ -84,43 +81,47 @@ dso_dl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_dl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -dso_dl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -dso_dl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_dl.c +dso_dl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h +dso_dl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +dso_dl.o: ../cryptlib.h dso_dl.c dso_dlfcn.o: ../../e_os.h ../../include/openssl/bio.h dso_dlfcn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_dlfcn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_dlfcn.o: ../../include/openssl/opensslconf.h -dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -dso_dlfcn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -dso_dlfcn.o: ../cryptlib.h dso_dlfcn.c +dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +dso_dlfcn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dso_dlfcn.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_dlfcn.c dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h dso_err.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -dso_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -dso_err.o: ../../include/openssl/symhacks.h dso_err.c +dso_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h +dso_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +dso_err.o: dso_err.c dso_lib.o: ../../e_os.h ../../include/openssl/bio.h dso_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_lib.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -dso_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -dso_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_lib.c +dso_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h +dso_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +dso_lib.o: ../cryptlib.h dso_lib.c dso_null.o: ../../e_os.h ../../include/openssl/bio.h dso_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_null.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_null.o: ../../include/openssl/opensslconf.h -dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -dso_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -dso_null.o: ../cryptlib.h dso_null.c +dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +dso_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dso_null.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_null.c dso_openssl.o: ../../e_os.h ../../include/openssl/bio.h dso_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_openssl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_openssl.o: ../../include/openssl/opensslconf.h dso_openssl.o: ../../include/openssl/opensslv.h +dso_openssl.o: ../../include/openssl/ossl_typ.h dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_openssl.c dso_vms.o: ../../e_os.h ../../include/openssl/bio.h @@ -128,13 +129,14 @@ dso_vms.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_vms.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -dso_vms.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -dso_vms.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_vms.c +dso_vms.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h +dso_vms.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +dso_vms.o: ../cryptlib.h dso_vms.c dso_win32.o: ../../e_os.h ../../include/openssl/bio.h dso_win32.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h dso_win32.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h dso_win32.o: ../../include/openssl/opensslconf.h -dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -dso_win32.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -dso_win32.o: ../cryptlib.h dso_win32.c +dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +dso_win32.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dso_win32.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_win32.c diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c index f7b4dfc0c3..417abb6ea9 100644 --- a/src/lib/libcrypto/dso/dso_dl.c +++ b/src/lib/libcrypto/dso/dso_dl.c @@ -1,4 +1,4 @@ -/* dso_dl.c */ +/* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2000. */ @@ -84,6 +84,7 @@ static int dl_finish(DSO *dso); static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); #endif static char *dl_name_converter(DSO *dso, const char *filename); +static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2); static DSO_METHOD dso_meth_dl = { "OpenSSL 'dl' shared library method", @@ -98,6 +99,7 @@ static DSO_METHOD dso_meth_dl = { #endif NULL, /* ctrl */ dl_name_converter, + dl_merger, NULL, /* init */ NULL /* finish */ }; @@ -239,6 +241,72 @@ static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname) return((DSO_FUNC_TYPE)sym); } +static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2) + { + char *merged; + + if(!filespec1 && !filespec2) + { + DSOerr(DSO_F_DL_MERGER, + ERR_R_PASSED_NULL_PARAMETER); + return(NULL); + } + /* If the first file specification is a rooted path, it rules. + same goes if the second file specification is missing. */ + if (!filespec2 || filespec1[0] == '/') + { + merged = OPENSSL_malloc(strlen(filespec1) + 1); + if(!merged) + { + DSOerr(DSO_F_DL_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + strcpy(merged, filespec1); + } + /* If the first file specification is missing, the second one rules. */ + else if (!filespec1) + { + merged = OPENSSL_malloc(strlen(filespec2) + 1); + if(!merged) + { + DSOerr(DSO_F_DL_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + strcpy(merged, filespec2); + } + else + /* This part isn't as trivial as it looks. It assumes that + the second file specification really is a directory, and + makes no checks whatsoever. Therefore, the result becomes + the concatenation of filespec2 followed by a slash followed + by filespec1. */ + { + int spec2len, len; + + spec2len = (filespec2 ? strlen(filespec2) : 0); + len = spec2len + (filespec1 ? strlen(filespec1) : 0); + + if(filespec2 && filespec2[spec2len - 1] == '/') + { + spec2len--; + len--; + } + merged = OPENSSL_malloc(len + 2); + if(!merged) + { + DSOerr(DSO_F_DL_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + strcpy(merged, filespec2); + merged[spec2len] = '/'; + strcpy(&merged[spec2len + 1], filespec1); + } + return(merged); + } + /* This function is identical to the one in dso_dlfcn.c, but as it is highly * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the * same time, there's no great duplicating the code. Figuring out an elegant @@ -282,36 +350,4 @@ static char *dl_name_converter(DSO *dso, const char *filename) return(translated); } -#ifdef OPENSSL_FIPS -static void dl_ref_point(){} - -int DSO_pathbyaddr(void *addr,char *path,int sz) - { - struct shl_descriptor inf; - int i,len; - - if (addr == NULL) - { - union { void(*f)(); void *p; } t = { dl_ref_point }; - addr = t.p; - } - - for (i=-1;shl_get_r(i,&inf)==0;i++) - { - if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) || - ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend)) - { - len = (int)strlen(inf.filename); - if (sz <= 0) return len+1; - if (len >= sz) len=sz-1; - memcpy(path,inf.filename,len); - path[len++] = 0; - return len; - } - } - - return -1; - } -#endif - #endif /* DSO_DL */ diff --git a/src/lib/libcrypto/dso/dso_vms.c b/src/lib/libcrypto/dso/dso_vms.c index 1674619d17..2c434ee8a6 100644 --- a/src/lib/libcrypto/dso/dso_vms.c +++ b/src/lib/libcrypto/dso/dso_vms.c @@ -1,4 +1,4 @@ -/* dso_vms.c */ +/* dso_vms.c -*- mode:C; c-file-style: "eay" -*- */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2000. */ @@ -63,6 +63,7 @@ #include #ifdef OPENSSL_SYS_VMS #pragma message disable DOLLARID +#include #include #include #include @@ -89,6 +90,8 @@ static int vms_finish(DSO *dso); static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg); #endif static char *vms_name_converter(DSO *dso, const char *filename); +static char *vms_merger(DSO *dso, const char *filespec1, + const char *filespec2); static DSO_METHOD dso_meth_vms = { "OpenSSL 'VMS' shared library method", @@ -103,6 +106,7 @@ static DSO_METHOD dso_meth_vms = { #endif NULL, /* ctrl */ vms_name_converter, + vms_merger, NULL, /* init */ NULL /* finish */ }; @@ -140,7 +144,7 @@ static int vms_load(DSO *dso) if(filename == NULL) { - DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME); + DSOerr(DSO_F_VMS_LOAD,DSO_R_NO_FILENAME); goto err; } @@ -295,19 +299,19 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym) if((dso == NULL) || (symname == NULL)) { - DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); + DSOerr(DSO_F_VMS_BIND_SYM,ERR_R_PASSED_NULL_PARAMETER); return; } if(sk_num(dso->meth_data) < 1) { - DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR); + DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_STACK_ERROR); return; } ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); if(ptr == NULL) { - DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE); + DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_NULL_HANDLE); return; } @@ -336,7 +340,7 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym) { errstring[length] = '\0'; - DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE); + DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_SYM_FAILURE); if (ptr->imagename_dsc.dsc$w_length) ERR_add_error_data(9, "Symbol ", symname, @@ -368,6 +372,127 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname) return sym; } +static char *vms_merger(DSO *dso, const char *filespec1, const char *filespec2) + { + int status; + int filespec1len, filespec2len; + struct FAB fab; +#ifdef NAML$C_MAXRSS + struct NAML nam; + char esa[NAML$C_MAXRSS]; +#else + struct NAM nam; + char esa[NAM$C_MAXRSS]; +#endif + char *merged; + + if (!filespec1) filespec1 = ""; + if (!filespec2) filespec2 = ""; + filespec1len = strlen(filespec1); + filespec2len = strlen(filespec2); + + fab = cc$rms_fab; +#ifdef NAML$C_MAXRSS + nam = cc$rms_naml; +#else + nam = cc$rms_nam; +#endif + + fab.fab$l_fna = (char *)filespec1; + fab.fab$b_fns = filespec1len; + fab.fab$l_dna = (char *)filespec2; + fab.fab$b_dns = filespec2len; +#ifdef NAML$C_MAXRSS + if (filespec1len > NAM$C_MAXRSS) + { + fab.fab$l_fna = 0; + fab.fab$b_fns = 0; + nam.naml$l_long_filename = (char *)filespec1; + nam.naml$l_long_filename_size = filespec1len; + } + if (filespec2len > NAM$C_MAXRSS) + { + fab.fab$l_dna = 0; + fab.fab$b_dns = 0; + nam.naml$l_long_defname = (char *)filespec2; + nam.naml$l_long_defname_size = filespec2len; + } + nam.naml$l_esa = esa; + nam.naml$b_ess = NAM$C_MAXRSS; + nam.naml$l_long_expand = esa; + nam.naml$l_long_expand_alloc = sizeof(esa); + nam.naml$b_nop = NAM$M_SYNCHK | NAM$M_PWD; + nam.naml$v_no_short_upcase = 1; + fab.fab$l_naml = &nam; +#else + nam.nam$l_esa = esa; + nam.nam$b_ess = NAM$C_MAXRSS; + nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_PWD; + fab.fab$l_nam = &nam; +#endif + + status = sys$parse(&fab, 0, 0); + + if(!$VMS_STATUS_SUCCESS(status)) + { + unsigned short length; + char errstring[257]; + struct dsc$descriptor_s errstring_dsc; + + errstring_dsc.dsc$w_length = sizeof(errstring); + errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T; + errstring_dsc.dsc$b_class = DSC$K_CLASS_S; + errstring_dsc.dsc$a_pointer = errstring; + + status = sys$getmsg(status, &length, &errstring_dsc, 1, 0); + + if (!$VMS_STATUS_SUCCESS(status)) + lib$signal(status); /* This is really bad. Abort! */ + else + { + errstring[length] = '\0'; + + DSOerr(DSO_F_VMS_MERGER,DSO_R_FAILURE); + ERR_add_error_data(7, + "filespec \"", filespec1, "\", ", + "defaults \"", filespec2, "\": ", + errstring); + } + return(NULL); + } +#ifdef NAML$C_MAXRSS + if (nam.naml$l_long_expand_size) + { + merged = OPENSSL_malloc(nam.naml$l_long_expand_size + 1); + if(!merged) + goto malloc_err; + strncpy(merged, nam.naml$l_long_expand, + nam.naml$l_long_expand_size); + merged[nam.naml$l_long_expand_size] = '\0'; + } + else + { + merged = OPENSSL_malloc(nam.naml$b_esl + 1); + if(!merged) + goto malloc_err; + strncpy(merged, nam.naml$l_esa, + nam.naml$b_esl); + merged[nam.naml$b_esl] = '\0'; + } +#else + merged = OPENSSL_malloc(nam.nam$b_esl + 1); + if(!merged) + goto malloc_err; + strncpy(merged, nam.nam$l_esa, + nam.nam$b_esl); + merged[nam.nam$b_esl] = '\0'; +#endif + return(merged); + malloc_err: + DSOerr(DSO_F_VMS_MERGER, + ERR_R_MALLOC_FAILURE); + } + static char *vms_name_converter(DSO *dso, const char *filename) { int len = strlen(filename); diff --git a/src/lib/libcrypto/dso/dso_win32.c b/src/lib/libcrypto/dso/dso_win32.c index cc4ac68696..fd3dd6a7fe 100644 --- a/src/lib/libcrypto/dso/dso_win32.c +++ b/src/lib/libcrypto/dso/dso_win32.c @@ -1,4 +1,4 @@ -/* dso_win32.c */ +/* dso_win32.c -*- mode:C; c-file-style: "eay" -*- */ /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL * project 2000. */ @@ -85,6 +85,26 @@ static FARPROC GetProcAddressA(HMODULE hModule,LPCSTR lpProcName) # endif # undef GetProcAddress # define GetProcAddress GetProcAddressA + +static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName) + { + WCHAR *fnamw; + size_t len_0=strlen(lpLibFileName)+1,i; + +#ifdef _MSC_VER + fnamw = (WCHAR *)_alloca (len_0*sizeof(WCHAR)); +#else + fnamw = (WCHAR *)alloca (len_0*sizeof(WCHAR)); +#endif + if (fnamw == NULL) return NULL; + +#if defined(_WIN32_WCE) && _WIN32_WCE>=101 + if (!MultiByteToWideChar(CP_ACP,0,lpLibFileName,len_0,fnamw,len_0)) +#endif + for (i=0;inode = start; + } + + do + { + last = filename[0]; + switch(last) + { + case ':': + if(position != IN_DEVICE) + { + DSOerr(DSO_F_WIN32_SPLITTER, + DSO_R_INCORRECT_FILE_SYNTAX); + /*goto err;*/ + return(NULL); + } + result->device = start; + result->devicelen = filename - start; + position = IN_FILE; + start = ++filename; + result->dir = start; + break; + case '\\': + case '/': + if(position == IN_NODE) + { + result->nodelen = filename - start; + position = IN_FILE; + start = ++filename; + result->dir = start; + } + else if(position == IN_DEVICE) + { + position = IN_FILE; + filename++; + result->dir = start; + result->dirlen = filename - start; + start = filename; + } + else + { + filename++; + result->dirlen += filename - start; + start = filename; + } + break; + case '\0': + if(position == IN_NODE) + { + result->nodelen = filename - start; + } + else + { + if(filename - start > 0) + { + if (assume_last_is_dir) + { + if (position == IN_DEVICE) + { + result->dir = start; + result->dirlen = 0; + } + result->dirlen += + filename - start; + } + else + { + result->file = start; + result->filelen = + filename - start; + } + } + } + break; + default: + filename++; + break; + } + } + while(last); + + if(!result->nodelen) result->node = NULL; + if(!result->devicelen) result->device = NULL; + if(!result->dirlen) result->dir = NULL; + if(!result->filelen) result->file = NULL; + + return(result); + } + +static char *win32_joiner(DSO *dso, const struct file_st *file_split) + { + int len = 0, offset = 0; + char *result = NULL; + const char *start; + + if(!file_split) + { + DSOerr(DSO_F_WIN32_JOINER, + ERR_R_PASSED_NULL_PARAMETER); + return(NULL); + } + if(file_split->node) + { + len += 2 + file_split->nodelen; /* 2 for starting \\ */ + if(file_split->predir || file_split->dir || file_split->file) + len++; /* 1 for ending \ */ + } + else if(file_split->device) + { + len += file_split->devicelen + 1; /* 1 for ending : */ + } + len += file_split->predirlen; + if(file_split->predir && (file_split->dir || file_split->file)) + { + len++; /* 1 for ending \ */ + } + len += file_split->dirlen; + if(file_split->dir && file_split->file) + { + len++; /* 1 for ending \ */ + } + len += file_split->filelen; + + if(!len) + { + DSOerr(DSO_F_WIN32_JOINER, DSO_R_EMPTY_FILE_STRUCTURE); + return(NULL); + } + + result = OPENSSL_malloc(len + 1); + if (!result) + { + DSOerr(DSO_F_WIN32_JOINER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + + if(file_split->node) + { + strcpy(&result[offset], "\\\\"); offset += 2; + strncpy(&result[offset], file_split->node, + file_split->nodelen); offset += file_split->nodelen; + if(file_split->predir || file_split->dir || file_split->file) + { + result[offset] = '\\'; offset++; + } + } + else if(file_split->device) + { + strncpy(&result[offset], file_split->device, + file_split->devicelen); offset += file_split->devicelen; + result[offset] = ':'; offset++; + } + start = file_split->predir; + while(file_split->predirlen > (start - file_split->predir)) + { + const char *end = openssl_strnchr(start, '/', + file_split->predirlen - (start - file_split->predir)); + if(!end) + end = start + + file_split->predirlen + - (start - file_split->predir); + strncpy(&result[offset], start, + end - start); offset += end - start; + result[offset] = '\\'; offset++; + start = end + 1; + } +#if 0 /* Not needed, since the directory converter above already appeneded + a backslash */ + if(file_split->predir && (file_split->dir || file_split->file)) + { + result[offset] = '\\'; offset++; + } +#endif + start = file_split->dir; + while(file_split->dirlen > (start - file_split->dir)) + { + const char *end = openssl_strnchr(start, '/', + file_split->dirlen - (start - file_split->dir)); + if(!end) + end = start + + file_split->dirlen + - (start - file_split->dir); + strncpy(&result[offset], start, + end - start); offset += end - start; + result[offset] = '\\'; offset++; + start = end + 1; + } +#if 0 /* Not needed, since the directory converter above already appeneded + a backslash */ + if(file_split->dir && file_split->file) + { + result[offset] = '\\'; offset++; + } +#endif + strncpy(&result[offset], file_split->file, + file_split->filelen); offset += file_split->filelen; + result[offset] = '\0'; + return(result); + } + +static char *win32_merger(DSO *dso, const char *filespec1, const char *filespec2) + { + char *merged = NULL; + struct file_st *filespec1_split = NULL; + struct file_st *filespec2_split = NULL; + + if(!filespec1 && !filespec2) + { + DSOerr(DSO_F_WIN32_MERGER, + ERR_R_PASSED_NULL_PARAMETER); + return(NULL); + } + if (!filespec2) + { + merged = OPENSSL_malloc(strlen(filespec1) + 1); + if(!merged) + { + DSOerr(DSO_F_WIN32_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + strcpy(merged, filespec1); + } + else if (!filespec1) + { + merged = OPENSSL_malloc(strlen(filespec2) + 1); + if(!merged) + { + DSOerr(DSO_F_WIN32_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + strcpy(merged, filespec2); + } + else + { + filespec1_split = win32_splitter(dso, filespec1, 0); + if (!filespec1_split) + { + DSOerr(DSO_F_WIN32_MERGER, + ERR_R_MALLOC_FAILURE); + return(NULL); + } + filespec2_split = win32_splitter(dso, filespec2, 1); + if (!filespec2_split) + { + DSOerr(DSO_F_WIN32_MERGER, + ERR_R_MALLOC_FAILURE); + OPENSSL_free(filespec1_split); + return(NULL); + } + + /* Fill in into filespec1_split */ + if (!filespec1_split->node && !filespec1_split->device) + { + filespec1_split->node = filespec2_split->node; + filespec1_split->nodelen = filespec2_split->nodelen; + filespec1_split->device = filespec2_split->device; + filespec1_split->devicelen = filespec2_split->devicelen; + } + if (!filespec1_split->dir) + { + filespec1_split->dir = filespec2_split->dir; + filespec1_split->dirlen = filespec2_split->dirlen; + } + else if (filespec1_split->dir[0] != '\\' + && filespec1_split->dir[0] != '/') + { + filespec1_split->predir = filespec2_split->dir; + filespec1_split->predirlen = filespec2_split->dirlen; + } + if (!filespec1_split->file) + { + filespec1_split->file = filespec2_split->file; + filespec1_split->filelen = filespec2_split->filelen; + } + + merged = win32_joiner(dso, filespec1_split); + } + return(merged); + } + static char *win32_name_converter(DSO *dso, const char *filename) { char *translated; @@ -295,4 +644,17 @@ static char *win32_name_converter(DSO *dso, const char *filename) return(translated); } +static const char *openssl_strnchr(const char *string, int c, size_t len) + { + size_t i; + const char *p; + for (i = 0, p = string; i < len && *p; i++, p++) + { + if (*p == c) + return p; + } + return NULL; + } + + #endif /* OPENSSL_SYS_WIN32 */ -- cgit v1.2.3-55-g6feb