1 /* $NetBSD: checkdll.c,v 1.3 2014/12/10 04:37:56 christos Exp $ */
4 * checkdll.c - Winsock DLL/IDN processing status
8 * Copyright (c) 2000,2002 Japan Network Information Center.
11 * By using this file, you agree to the terms and conditions set forth bellow.
13 * LICENSE TERMS AND CONDITIONS
15 * The following License Terms and Conditions apply, unless a different
16 * license is obtained from Japan Network Information Center ("JPNIC"),
17 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
18 * Chiyoda-ku, Tokyo 101-0047, Japan.
20 * 1. Use, Modification and Redistribution (including distribution of any
21 * modified or derived work) in source and/or binary forms is permitted
22 * under this License Terms and Conditions.
24 * 2. Redistribution of source code must retain the copyright notices as they
25 * appear in each source code file, this License Terms and Conditions.
27 * 3. Redistribution in binary form must reproduce the Copyright Notice,
28 * this License Terms and Conditions, in the documentation and/or other
29 * materials provided with the distribution. For the purposes of binary
30 * distribution the "Copyright Notice" refers to the following language:
31 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
33 * 4. The name of JPNIC may not be used to endorse or promote products
34 * derived from this Software without specific prior written approval of
37 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
40 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
46 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
54 #include "wrapcommon.h"
56 static int winsock_idx
; /* index of winsock_info[] */
58 static struct winsock_type
{
59 char *version
; /* winsock version */
60 char *name
; /* wrapper DLL name */
61 char *original_name
; /* original DLL name */
63 #define IDN_IDX_WS11 0
64 { "1.1", "WSOCK32", "WSOCK32O" },
65 #define IDN_IDX_WS20 1
66 { "2.0", "WS2_32", "WS2_32O" },
70 static HINSTANCE
load_original_dll(void);
71 static BOOL
check_idn_processing(void);
72 static BOOL
check_dll(const char *name
);
75 idnWinsockVersion(const char *version
) {
77 for (i
= 0; winsock_info
[i
].version
!= NULL
; i
++) {
78 if (strcmp(winsock_info
[i
].version
, version
) == 0) {
80 idnLogPrintf(idn_log_level_trace
,
81 "idnWinsockVersion: version %s\n",
86 idnLogPrintf(idn_log_level_fatal
,
87 "idnWinsockVersion: unknown winsock version %s\n",
93 idnWinsockHandle(void) {
94 static HINSTANCE dll_handle
= NULL
;
95 static int initialized
= 0;
98 /* Get the handle of the original winsock DLL */
99 idnLogPrintf(idn_log_level_trace
,
100 "idnWinsockHandle: loading original DLL..\n");
101 dll_handle
= load_original_dll();
108 idnGetContext(void) {
109 static int initialized
= 0;
110 static idn_resconf_t ctx
= NULL
;
114 * Check whether IDN processing should be done
115 * in this wrapper DLL.
117 idnLogPrintf(idn_log_level_trace
,
118 "idnGetContext: checking IDN status..\n");
119 if (check_idn_processing()) {
120 /* Initialize idnkit */
122 idnLogPrintf(idn_log_level_info
,
123 "Processing context: %08x\n", ctx
);
125 idnLogPrintf(idn_log_level_info
,
126 "NOT process IDN here\n");
136 load_original_dll(void) {
140 char dllpath
[MAX_PATH
];
141 const char *dll_name
= winsock_info
[winsock_idx
].original_name
;
145 * Get idn wrapper's install directory, where the copies of
146 * the original winsock DLLs are saved.
149 if (idnGetInstallDir(dllpath
, sizeof(dllpath
)) != TRUE
) {
150 idnLogPrintf(idn_log_level_fatal
,
151 "idnWinsockHandle: cannot find idn wrapper's "
152 "install directory\n");
154 return (NULL
); /* for lint */
156 /* Strip the trailing backslash. */
157 if (dllpath
[0] != '\0' &&
158 dllpath
[strlen(dllpath
) - 1] == '\\') {
159 dllpath
[strlen(dllpath
) - 1] = '\0';
161 /* Is the pathname is insanely long? */
162 if (strlen(dllpath
) + strlen(dll_name
) + 1 + 4 >= sizeof(dllpath
)) {
163 idnLogPrintf(idn_log_level_fatal
,
164 "idnWinsockHandle: idn wrapper's install path is "
165 "too long to be true\n");
167 return (NULL
); /* for lint */
169 /* Append the DLL name to form a full pathname of the DLL. */
170 strcat(dllpath
, "\\");
171 strcat(dllpath
, dll_name
);
172 strcat(dllpath
, ".DLL");
174 idnLogPrintf(idn_log_level_trace
,
175 "idnWinsockHandle: loading original winsock DLL (%s)\n",
177 if ((handle
= LoadLibrary(dllpath
)) == NULL
) {
178 idnLogPrintf(idn_log_level_fatal
,
179 "idnWinsockHandle: no DLL %-.100s\n", dllpath
);
181 return (NULL
); /* font lint */
187 check_idn_processing(void) {
188 int where
= idnEncodeWhere();
191 idnLogPrintf(idn_log_level_trace
,
192 "idnGetContext: Winsock%s, where=%d\n",
193 winsock_info
[winsock_idx
].version
, where
);
195 switch (winsock_idx
) {
198 case IDN_ENCODE_ALWAYS
:
199 case IDN_ENCODE_ONLY11
:
201 case IDN_ENCODE_CHECK
:
202 if (!check_dll(winsock_info
[winsock_idx
].name
)) {
210 case IDN_ENCODE_ALWAYS
:
211 case IDN_ENCODE_ONLY20
:
212 case IDN_ENCODE_CHECK
:
222 check_dll(const char *name
) {
223 HINSTANCE hdll
= NULL
;
226 hdll
= LoadLibrary(name
);
229 * Just check the existence of the named DLL, without taking
230 * the trouble of calling DllMain.
232 hdll
= LoadLibraryEx(name
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
235 idnLogPrintf(idn_log_level_trace
,
236 "idnGetContext: DLL %s does not exist\n");
239 idnLogPrintf(idn_log_level_trace
,
240 "idnGetContext: DLL %s exists\n");