View | Details | Raw Unified | Return to bug 183153
Collapse All | Expand All

(-)contrib/smbfs/lib/smb/nls.c (-52 / +15 lines)
Lines 36-47 Link Here
36
__FBSDID("$FreeBSD$");
36
__FBSDID("$FreeBSD$");
37
37
38
#include <sys/types.h>
38
#include <sys/types.h>
39
#include <sys/iconv.h>
39
#include <iconv.h>
40
#include <sys/sysctl.h>
40
#include <sys/sysctl.h>
41
#include <ctype.h>
41
#include <ctype.h>
42
#ifndef APPLE
43
#include <dlfcn.h>
44
#endif
45
#include <errno.h>
42
#include <errno.h>
46
#include <stdio.h>
43
#include <stdio.h>
47
#include <string.h>
44
#include <string.h>
Lines 50-70 Link Here
50
#include <err.h>
47
#include <err.h>
51
#include <netsmb/smb_lib.h>
48
#include <netsmb/smb_lib.h>
52
49
53
/*
54
 * prototype iconv* functions
55
 */
56
typedef void *iconv_t;
57
58
static iconv_t (*my_iconv_open)(const char *, const char *);
59
static size_t(*my_iconv)(iconv_t, const char **, size_t *, char **, size_t *);
60
static int(*my_iconv_close)(iconv_t);
61
62
u_char nls_lower[256];
50
u_char nls_lower[256];
63
u_char nls_upper[256];
51
u_char nls_upper[256];
64
52
65
static iconv_t nls_toext, nls_toloc;
53
static iconv_t nls_toext, nls_toloc;
66
static int iconv_loaded;
67
static void *iconv_lib;
68
54
69
int
55
int
70
nls_setlocale(const char *name)
56
nls_setlocale(const char *name)
Lines 90-121 Link Here
90
#else
76
#else
91
	iconv_t icd;
77
	iconv_t icd;
92
78
93
	if (iconv_loaded == 2)
94
		return ENOENT;
95
	else if (iconv_loaded == 0) {
96
		iconv_loaded++;
97
		iconv_lib = dlopen("libiconv.so", RTLD_LAZY | RTLD_GLOBAL);
98
		if (iconv_lib == NULL) {
99
			warn("Unable to load iconv library: %s\n", dlerror());
100
			iconv_loaded++;
101
			return ENOENT;
102
		}
103
		my_iconv_open = dlsym(iconv_lib, "iconv_open");
104
		my_iconv = dlsym(iconv_lib, "iconv");
105
		my_iconv_close = dlsym(iconv_lib, "iconv_close");
106
	}
107
	if (nls_toext)
79
	if (nls_toext)
108
		my_iconv_close(nls_toext);
80
		iconv_close(nls_toext);
109
	if (nls_toloc)
81
	if (nls_toloc)
110
		my_iconv_close(nls_toloc);
82
		iconv_close(nls_toloc);
111
	nls_toext = nls_toloc = (iconv_t)0;
83
	nls_toext = nls_toloc = (iconv_t)0;
112
	icd = my_iconv_open(external, local);
84
	icd = iconv_open(external, local);
113
	if (icd == (iconv_t)-1)
85
	if (icd == (iconv_t)-1)
114
		return errno;
86
		return errno;
115
	nls_toext = icd;
87
	nls_toext = icd;
116
	icd = my_iconv_open(local, external);
88
	icd = iconv_open(local, external);
117
	if (icd == (iconv_t)-1) {
89
	if (icd == (iconv_t)-1) {
118
		my_iconv_close(nls_toext);
90
		iconv_close(nls_toext);
119
		nls_toext = (iconv_t)0;
91
		nls_toext = (iconv_t)0;
120
		return errno;
92
		return errno;
121
	}
93
	}
Lines 130-143 Link Here
130
	char *p = dst;
102
	char *p = dst;
131
	size_t inlen, outlen;
103
	size_t inlen, outlen;
132
104
133
	if (!iconv_loaded)
134
		return strcpy(dst, src);
135
136
	if (nls_toloc == (iconv_t)0)
105
	if (nls_toloc == (iconv_t)0)
137
		return strcpy(dst, src);
106
		return strcpy(dst, src);
138
	inlen = outlen = strlen(src);
107
	inlen = outlen = strlen(src);
139
	my_iconv(nls_toloc, NULL, NULL, &p, &outlen);
108
	iconv(nls_toloc, NULL, NULL, &p, &outlen);
140
	while (my_iconv(nls_toloc, &src, &inlen, &p, &outlen) == -1) {
109
	while (iconv(nls_toloc, &src, &inlen, &p, &outlen) == -1) {
141
		*p++ = *src++;
110
		*p++ = *src++;
142
		inlen--;
111
		inlen--;
143
		outlen--;
112
		outlen--;
Lines 152-165 Link Here
152
	char *p = dst;
121
	char *p = dst;
153
	size_t inlen, outlen;
122
	size_t inlen, outlen;
154
123
155
	if (!iconv_loaded)
156
		return strcpy(dst, src);
157
158
	if (nls_toext == (iconv_t)0)
124
	if (nls_toext == (iconv_t)0)
159
		return strcpy(dst, src);
125
		return strcpy(dst, src);
160
	inlen = outlen = strlen(src);
126
	inlen = outlen = strlen(src);
161
	my_iconv(nls_toext, NULL, NULL, &p, &outlen);
127
	iconv(nls_toext, NULL, NULL, &p, &outlen);
162
	while (my_iconv(nls_toext, &src, &inlen, &p, &outlen) == -1) {
128
	while (iconv(nls_toext, &src, &inlen, &p, &outlen) == -1) {
163
		*p++ = *src++;
129
		*p++ = *src++;
164
		inlen--;
130
		inlen--;
165
		outlen--;
131
		outlen--;
Lines 175-183 Link Here
175
	const char *s = src;
141
	const char *s = src;
176
	size_t inlen, outlen;
142
	size_t inlen, outlen;
177
143
178
	if (!iconv_loaded)
179
		return memcpy(dst, src, size);
180
181
	if (size == 0)
144
	if (size == 0)
182
		return NULL;
145
		return NULL;
183
146
Lines 184-191 Link Here
184
	if (nls_toloc == (iconv_t)0)
147
	if (nls_toloc == (iconv_t)0)
185
		return memcpy(dst, src, size);
148
		return memcpy(dst, src, size);
186
	inlen = outlen = size;
149
	inlen = outlen = size;
187
	my_iconv(nls_toloc, NULL, NULL, &p, &outlen);
150
	iconv(nls_toloc, NULL, NULL, &p, &outlen);
188
	while (my_iconv(nls_toloc, &s, &inlen, &p, &outlen) == -1) {
151
	while (iconv(nls_toloc, &s, &inlen, &p, &outlen) == -1) {
189
		*p++ = *s++;
152
		*p++ = *s++;
190
		inlen--;
153
		inlen--;
191
		outlen--;
154
		outlen--;
Lines 203-214 Link Here
203
	if (size == 0)
166
	if (size == 0)
204
		return NULL;
167
		return NULL;
205
168
206
	if (!iconv_loaded || nls_toext == (iconv_t)0)
169
	if (nls_toext == (iconv_t)0)
207
		return memcpy(dst, src, size);
170
		return memcpy(dst, src, size);
208
171
209
	inlen = outlen = size;
172
	inlen = outlen = size;
210
	my_iconv(nls_toext, NULL, NULL, &p, &outlen);
173
	iconv(nls_toext, NULL, NULL, &p, &outlen);
211
	while (my_iconv(nls_toext, &s, &inlen, &p, &outlen) == -1) {
174
	while (iconv(nls_toext, &s, &inlen, &p, &outlen) == -1) {
212
		*p++ = *s++;
175
		*p++ = *s++;
213
		inlen--;
176
		inlen--;
214
		outlen--;
177
		outlen--;
(-)usr.sbin/mount_smbfs/Makefile (-5 lines)
Lines 11-21 Link Here
11
LDADD=	-lsmb -lkiconv
11
LDADD=	-lsmb -lkiconv
12
DPADD=	${LIBSMB} ${LIBKICONV}
12
DPADD=	${LIBSMB} ${LIBKICONV}
13
13
14
# Needs to be dynamically linked for optional dlopen() access to
15
# userland libiconv (see the -E option).
16
#
17
NO_SHARED?=	NO
18
19
.PATH:	${CONTRIBDIR}/mount_smbfs
14
.PATH:	${CONTRIBDIR}/mount_smbfs
20
.PATH:  ${MOUNTDIR}
15
.PATH:  ${MOUNTDIR}

Return to bug 183153