From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/lib/iconv.c | 346 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 source3/lib/iconv.c (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c new file mode 100644 index 0000000000..a22c84997d --- /dev/null +++ b/source3/lib/iconv.c @@ -0,0 +1,346 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + minimal iconv implementation + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static size_t ascii_pull(char **, size_t *, char **, size_t *); +static size_t ascii_push(char **, size_t *, char **, size_t *); +static size_t weird_pull(char **, size_t *, char **, size_t *); +static size_t weird_push(char **, size_t *, char **, size_t *); +static size_t iconv_copy(char **, size_t *, char **, size_t *); + +/* + for each charset we have a function that pulls from that charset to + a ucs2 buffer, and a function that pushes to a ucs2 buffer +*/ +static struct { + char *name; + size_t (*pull)(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + size_t (*push)(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); +} charsets[] = { + {"UCS2", iconv_copy, iconv_copy}, + {"ASCII", ascii_pull, ascii_push}, + {"WEIRD", weird_pull, weird_push}, + {NULL, NULL, NULL} +}; + +/* + this is a simple portable iconv() implementaion. It only knows about + a very small number of character sets - just enough that Samba works + on systems that don't have iconv + */ +size_t smb_iconv(smb_iconv_t cd, + char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + char cvtbuf[2048]; + char *bufp = cvtbuf; + size_t bufsize; + +#ifdef HAVE_NATIVE_ICONV + if (cd->cd) { + return iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); + } +#endif + + if (!inbuf || ! *inbuf || !outbuf || ! *outbuf) return 0; + + /* in most cases we can go direct */ + if (cd->direct) { + return cd->direct(inbuf, inbytesleft, outbuf, outbytesleft); + } + + /* otherwise we have to do it chunks at a time */ + while (*inbytesleft > 0) { + bufp = cvtbuf; + bufsize = sizeof(cvtbuf); + if (cd->pull(inbuf, inbytesleft, &bufp, &bufsize) == -1 && + errno != E2BIG) return -1; + + bufp = cvtbuf; + bufsize = sizeof(cvtbuf) - bufsize; + if (cd->push(&bufp, &bufsize, outbuf, outbytesleft) == -1) return -1; + } + + return 0; +} + +/* + simple iconv_open() wrapper + */ +smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) +{ + smb_iconv_t ret; + int from, to; +#ifdef HAVE_NATIVE_ICONV + iconv_t cd = NULL; +#endif + + for (from=0; charsets[from].name; from++) { + if (strcasecmp(charsets[from].name, fromcode) == 0) break; + } + for (to=0; charsets[to].name; to++) { + if (strcasecmp(charsets[to].name, tocode) == 0) break; + } + + if (!charsets[from].name || !charsets[to].name) { +#ifdef HAVE_NATIVE_ICONV + cd = iconv_open(tocode, fromcode); + if (!cd) +#endif + { + errno = EINVAL; + return (smb_iconv_t)-1; + } + } + + ret = (smb_iconv_t)malloc(sizeof(*ret)); + if (!ret) { + errno = ENOMEM; + return (smb_iconv_t)-1; + } + memset(ret, 0, sizeof(*ret)); + +#ifdef HAVE_NATIVE_ICONV + /* see if we wil be using the native iconv */ + if (cd) { + ret->cd = cd; + return ret; + } +#endif + + /* check for the simplest null conversion */ + if (from == to) { + ret->direct = iconv_copy; + return ret; + } + + /* check for conversion to/from ucs2 */ + if (from == 0) { + ret->direct = charsets[to].push; + return ret; + } + if (to == 0) { + ret->direct = charsets[from].pull; + return ret; + } + + /* the general case has to go via a buffer */ + ret->pull = charsets[from].pull; + ret->push = charsets[to].push; + return ret; +} + +/* + simple iconv_close() wrapper +*/ +int smb_iconv_close (smb_iconv_t cd) +{ +#ifdef HAVE_NATIVE_ICONV + if (cd->cd) { + iconv_close(cd->cd); + } +#endif + memset(cd, 0, sizeof(*cd)); + free(cd); + return 0; +} + + +/********************************************************************** + the following functions implement the builtin character sets in Samba + and also the "test" character sets that are designed to test + multi-byte character set support for english users +***********************************************************************/ + +static size_t ascii_pull(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[1] = 0; + (*inbytesleft) -= 1; + (*outbytesleft) -= 2; + (*inbuf) += 1; + (*outbuf) += 2; + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t ascii_push(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int ir_count=0; + + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + (*outbuf)[0] = (*inbuf)[0]; + if ((*inbuf)[1]) ir_count++; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return ir_count; +} + + +/* the "weird" character set is very useful for testing multi-byte + support and finding bugs. Don't use on a production system! +*/ +static struct { + char from; + char *to; + int len; +} weird_table[] = { + {'q', "^q^", 3}, + {'Q', "^Q^", 3}, + {'x', "\\.q\\.", 5}, + {'X', "\\.Z\\.", 5}, + {0, NULL} +}; + +static size_t weird_pull(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + int i; + for (i=0;weird_table[i].from;i++) { + if (strncmp((*inbuf), + weird_table[i].to, + weird_table[i].len) == 0) { + if (*inbytesleft < weird_table[i].len) { + DEBUG(0,("ERROR: truncated weird string\n")); + smb_panic(__FUNCTION__); + + } else { + (*outbuf)[0] = weird_table[i].from; + (*outbuf)[1] = 0; + (*inbytesleft) -= weird_table[i].len; + (*outbytesleft) -= 2; + (*inbuf) += weird_table[i].len; + (*outbuf) += 2; + goto next; + } + } + } + (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[1] = 0; + (*inbytesleft) -= 1; + (*outbytesleft) -= 2; + (*inbuf) += 1; + (*outbuf) += 2; + next: + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t weird_push(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int ir_count=0; + + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + int i; + for (i=0;weird_table[i].from;i++) { + if ((*inbuf)[0] == weird_table[i].from && + (*inbuf)[1] == 0) { + if (*outbytesleft < weird_table[i].len) { + DEBUG(0,("No room for weird character\n")); + smb_panic(__FUNCTION__); + } else { + memcpy(*outbuf, weird_table[i].to, + weird_table[i].len); + (*inbytesleft) -= 2; + (*outbytesleft) -= weird_table[i].len; + (*inbuf) += 2; + (*outbuf) += weird_table[i].len; + goto next; + } + } + } + (*outbuf)[0] = (*inbuf)[0]; + if ((*inbuf)[1]) ir_count++; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + next: + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return ir_count; +} + +static size_t iconv_copy(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int n; + + n = MIN(*inbytesleft, *outbytesleft); + + memmove(*outbuf, *inbuf, n); + + (*inbytesleft) -= n; + (*outbytesleft) -= n; + (*inbuf) += n; + (*outbuf) += n; + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} -- cgit From f51260a65eaa73f60848903d2bf64abec8305a9b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 08:03:47 +0000 Subject: got rid of __FUNCTION__ debug (This used to be commit 815ca752744c2ae93390445f4bb6532d396bbc59) --- source3/lib/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index a22c84997d..0b685d18ea 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -247,7 +247,7 @@ static size_t weird_pull(char **inbuf, size_t *inbytesleft, weird_table[i].len) == 0) { if (*inbytesleft < weird_table[i].len) { DEBUG(0,("ERROR: truncated weird string\n")); - smb_panic(__FUNCTION__); + smb_panic("weird_pull"); } else { (*outbuf)[0] = weird_table[i].from; @@ -289,7 +289,7 @@ static size_t weird_push(char **inbuf, size_t *inbytesleft, (*inbuf)[1] == 0) { if (*outbytesleft < weird_table[i].len) { DEBUG(0,("No room for weird character\n")); - smb_panic(__FUNCTION__); + smb_panic("weird_push"); } else { memcpy(*outbuf, weird_table[i].to, weird_table[i].len); -- cgit From 33b550e47ba63782f7a35af265b0b452a9c426dd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 12:16:24 +0000 Subject: portability fixes (This used to be commit 7a5c24c219d8b19f2c3cd11fdde3ebcede0646a2) --- source3/lib/iconv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 0b685d18ea..6dfdf3adf1 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -241,6 +241,7 @@ static size_t weird_pull(char **inbuf, size_t *inbytesleft, { while (*inbytesleft >= 1 && *outbytesleft >= 2) { int i; + int done = 0; for (i=0;weird_table[i].from;i++) { if (strncmp((*inbuf), weird_table[i].to, @@ -256,17 +257,18 @@ static size_t weird_pull(char **inbuf, size_t *inbytesleft, (*outbytesleft) -= 2; (*inbuf) += weird_table[i].len; (*outbuf) += 2; - goto next; + done = 1; + break; } } } + if (done) continue; (*outbuf)[0] = (*inbuf)[0]; (*outbuf)[1] = 0; (*inbytesleft) -= 1; (*outbytesleft) -= 2; (*inbuf) += 1; (*outbuf) += 2; - next: } if (*inbytesleft > 0) { @@ -284,6 +286,7 @@ static size_t weird_push(char **inbuf, size_t *inbytesleft, while (*inbytesleft >= 2 && *outbytesleft >= 1) { int i; + int done=0; for (i=0;weird_table[i].from;i++) { if ((*inbuf)[0] == weird_table[i].from && (*inbuf)[1] == 0) { @@ -297,17 +300,19 @@ static size_t weird_push(char **inbuf, size_t *inbytesleft, (*outbytesleft) -= weird_table[i].len; (*inbuf) += 2; (*outbuf) += weird_table[i].len; - goto next; + done = 1; + break; } } } + if (done) continue; + (*outbuf)[0] = (*inbuf)[0]; if ((*inbuf)[1]) ir_count++; (*inbytesleft) -= 2; (*outbytesleft) -= 1; (*inbuf) += 2; (*outbuf) += 1; - next: } if (*inbytesleft == 1) { -- cgit From 681c3100ed4d917edb91d1acd715b25b6f2702a9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 14:41:06 +0000 Subject: more portability fixes (This used to be commit bf818268516cfbebcdeacbb0528395e9bbb8e442) --- source3/lib/iconv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6dfdf3adf1..03e63be5e6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -231,8 +231,6 @@ static struct { } weird_table[] = { {'q', "^q^", 3}, {'Q', "^Q^", 3}, - {'x', "\\.q\\.", 5}, - {'X', "\\.Z\\.", 5}, {0, NULL} }; @@ -248,7 +246,7 @@ static size_t weird_pull(char **inbuf, size_t *inbytesleft, weird_table[i].len) == 0) { if (*inbytesleft < weird_table[i].len) { DEBUG(0,("ERROR: truncated weird string\n")); - smb_panic("weird_pull"); + /* smb_panic("weird_pull"); */ } else { (*outbuf)[0] = weird_table[i].from; @@ -292,7 +290,7 @@ static size_t weird_push(char **inbuf, size_t *inbytesleft, (*inbuf)[1] == 0) { if (*outbytesleft < weird_table[i].len) { DEBUG(0,("No room for weird character\n")); - smb_panic("weird_push"); + /* smb_panic("weird_push"); */ } else { memcpy(*outbuf, weird_table[i].to, weird_table[i].len); -- cgit From 22325f6fdb54962ef65b823459523e6a1936a2a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 15:08:30 +0000 Subject: added builtin support for UTF8 (This used to be commit 76d83e7f704cf016308dccaad9bc42d57db97686) --- source3/lib/iconv.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 03e63be5e6..b03a146d4f 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -23,6 +23,8 @@ static size_t ascii_pull(char **, size_t *, char **, size_t *); static size_t ascii_push(char **, size_t *, char **, size_t *); +static size_t utf8_pull(char **, size_t *, char **, size_t *); +static size_t utf8_push(char **, size_t *, char **, size_t *); static size_t weird_pull(char **, size_t *, char **, size_t *); static size_t weird_push(char **, size_t *, char **, size_t *); static size_t iconv_copy(char **, size_t *, char **, size_t *); @@ -38,7 +40,8 @@ static struct { size_t (*push)(char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); } charsets[] = { - {"UCS2", iconv_copy, iconv_copy}, + {"UCS2", iconv_copy, iconv_copy}, + {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, {"WEIRD", weird_pull, weird_push}, {NULL, NULL, NULL} @@ -347,3 +350,114 @@ static size_t iconv_copy(char **inbuf, size_t *inbytesleft, return 0; } + +static size_t utf8_pull(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + unsigned char *c = (unsigned char *)*inbuf; + unsigned char *uc = (unsigned char *)*outbuf; + int len = 1; + + if ((c[0] & 0xf0) == 0xe0) { + if (*inbytesleft < 3) { + DEBUG(0,("short utf8 char\n")); + goto badseq; + } + uc[1] = ((c[0]&0xF)<<4) | ((c[1]>>2)&0xF); + uc[0] = (c[1]<<6) | (c[2]&0x3f); + len = 3; + } else if ((c[0] & 0xe0) == 0xc0) { + if (*inbytesleft < 2) { + DEBUG(0,("short utf8 char\n")); + goto badseq; + } + uc[1] = (c[0]>>2) & 0x7; + uc[0] = (c[0]<<6) | (c[1]&0x3f); + len = 2; + } else { + uc[0] = c[0]; + uc[1] = 0; + } + + (*inbuf) += len; + (*inbytesleft) -= len; + (*outbytesleft) -= 2; + (*outbuf) += 2; + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; + +badseq: + errno = EINVAL; + return -1; +} + +static size_t utf8_push(char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + unsigned char *c = (unsigned char *)*outbuf; + unsigned char *uc = (unsigned char *)*inbuf; + int len=1; + + if ((uc[1] & 0xf8) == 0xd8) { + if (*outbytesleft < 3) { + DEBUG(0,("short utf8 write\n")); + goto toobig; + } + c[0] = 0xed; + c[1] = 0x9f; + c[2] = 0xbf; + len = 3; + } else if (uc[1] & 0xf8) { + if (*outbytesleft < 3) { + DEBUG(0,("short utf8 write\n")); + goto toobig; + } + c[0] = 0xe0 | (uc[1]>>4); + c[1] = 0x80 | ((uc[1]&0xF)<<2) | (uc[0]>>6); + c[2] = 0x80 | (uc[0]&0x3f); + len = 3; + } else if (uc[1] | (uc[0] & 0x80)) { + if (*outbytesleft < 2) { + DEBUG(0,("short utf8 write\n")); + goto toobig; + } + c[0] = 0xc0 | (uc[1]<<2) | (uc[0]>>6); + c[1] = 0x80 | (uc[0]&0x3f); + len = 2; + } else { + c[0] = uc[0]; + } + + + (*outbuf)[0] = (*inbuf)[0]; + (*inbytesleft) -= 2; + (*outbytesleft) -= len; + (*inbuf) += 2; + (*outbuf) += len; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return 0; + +toobig: + errno = E2BIG; + return -1; +} + -- cgit From ee3119cee66ec58896cada0ca5998faff05387bd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 5 Jul 2001 00:04:30 +0000 Subject: make sure we reset the shift state on error for charsets like SJIS (This used to be commit 42648a7aada48220fdfaf6acfe95b9614122f1da) --- source3/lib/iconv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index b03a146d4f..a5a7a847b5 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -62,7 +62,16 @@ size_t smb_iconv(smb_iconv_t cd, #ifdef HAVE_NATIVE_ICONV if (cd->cd) { - return iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); + size_t ret; + ret = iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); + + /* if there was an error then reset the internal state, + this ensures that we don't have a shift state remaining for + character sets like SJIS */ + if (ret == (size_t)-1) { + iconv(cd->cd, NULL, NULL, NULL, NULL); + } + return ret; } #endif -- cgit From fb50cf54e58ea99fd0788a540f7b86d2ba7e36b8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 5 Jul 2001 00:57:42 +0000 Subject: optimised the 7 bit case for utf8 conversion (This used to be commit 0c61e54f152eca6b7607fcce9ea512bc60a19060) --- source3/lib/iconv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index a5a7a847b5..07d42eed8f 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -368,7 +368,10 @@ static size_t utf8_pull(char **inbuf, size_t *inbytesleft, unsigned char *uc = (unsigned char *)*outbuf; int len = 1; - if ((c[0] & 0xf0) == 0xe0) { + if ((c[0] & 0x80) == 0) { + uc[0] = c[0]; + uc[1] = 0; + } else if ((c[0] & 0xf0) == 0xe0) { if (*inbytesleft < 3) { DEBUG(0,("short utf8 char\n")); goto badseq; @@ -384,9 +387,6 @@ static size_t utf8_pull(char **inbuf, size_t *inbytesleft, uc[1] = (c[0]>>2) & 0x7; uc[0] = (c[0]<<6) | (c[1]&0x3f); len = 2; - } else { - uc[0] = c[0]; - uc[1] = 0; } (*inbuf) += len; -- cgit From 9a0397cf698496cfbad42201eef96de21ecb7804 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jul 2001 00:14:56 +0000 Subject: added some comments and removed an unnecessary check (This used to be commit 25c4b3f19315bdef57041da79c12271b72015701) --- source3/lib/iconv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 07d42eed8f..0c722e71dd 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -75,8 +75,6 @@ size_t smb_iconv(smb_iconv_t cd, } #endif - if (!inbuf || ! *inbuf || !outbuf || ! *outbuf) return 0; - /* in most cases we can go direct */ if (cd->direct) { return cd->direct(inbuf, inbytesleft, outbuf, outbytesleft); @@ -117,6 +115,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) if (!charsets[from].name || !charsets[to].name) { #ifdef HAVE_NATIVE_ICONV + /* its not builtin - see if iconv() has it */ cd = iconv_open(tocode, fromcode); if (!cd) #endif @@ -134,7 +133,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) memset(ret, 0, sizeof(*ret)); #ifdef HAVE_NATIVE_ICONV - /* see if we wil be using the native iconv */ + /* see if we will be using the native iconv */ if (cd) { ret->cd = cd; return ret; -- cgit From 4b7c8070857e84c151bcec6ccb015cb0b219be8b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jul 2001 08:59:50 +0000 Subject: fixed a silly bug in the internal UTF8 implementation (This used to be commit 95a9a1814f1a1ac07c316cc920c7493a86d5a09b) --- source3/lib/iconv.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 0c722e71dd..e0988dc46a 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -63,8 +63,22 @@ size_t smb_iconv(smb_iconv_t cd, #ifdef HAVE_NATIVE_ICONV if (cd->cd) { size_t ret; +#if 0 + char *p = *outbuf; + char *q = *inbuf; + int inlen=*inbytesleft, outlen=*outbytesleft; +#endif + ret = iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); +#if 0 + if (strstr(p, "foo") || strstr(q, "foo")) { + DEBUG(0,("Foo 2!\n")); + dump_data(0, p, outlen - *outbytesleft); + dump_data(0, q, inlen - *inbytesleft); + } +#endif + /* if there was an error then reset the internal state, this ensures that we don't have a shift state remaining for character sets like SJIS */ @@ -445,7 +459,6 @@ static size_t utf8_push(char **inbuf, size_t *inbytesleft, } - (*outbuf)[0] = (*inbuf)[0]; (*inbytesleft) -= 2; (*outbytesleft) -= len; (*inbuf) += 2; -- cgit From 512351db92b4e13c2944f740090ec58730d8fa06 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 22 Jul 2001 00:27:30 +0000 Subject: switch from UCS2 to UCS-2LE (This used to be commit e236a3e29e4af24b20ec6af357ce67abf82b4528) --- source3/lib/iconv.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index e0988dc46a..b73ff6ff39 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -40,7 +40,7 @@ static struct { size_t (*push)(char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); } charsets[] = { - {"UCS2", iconv_copy, iconv_copy}, + {"UCS-2LE", iconv_copy, iconv_copy}, {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, {"WEIRD", weird_pull, weird_push}, @@ -63,22 +63,8 @@ size_t smb_iconv(smb_iconv_t cd, #ifdef HAVE_NATIVE_ICONV if (cd->cd) { size_t ret; -#if 0 - char *p = *outbuf; - char *q = *inbuf; - int inlen=*inbytesleft, outlen=*outbytesleft; -#endif - ret = iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); -#if 0 - if (strstr(p, "foo") || strstr(q, "foo")) { - DEBUG(0,("Foo 2!\n")); - dump_data(0, p, outlen - *outbytesleft); - dump_data(0, q, inlen - *inbytesleft); - } -#endif - /* if there was an error then reset the internal state, this ensures that we don't have a shift state remaining for character sets like SJIS */ -- cgit From 49514266131aa55b4a97f02b39b2d5e5c1f625a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 22 Jul 2001 07:38:32 +0000 Subject: changed the iconv interface to go via ucs2 for all conversions. This fixes some problems wih some character sets and allows for using internal charsets in conjunction with ionv charsets this makes us slower but more correct. speed will come later. (This used to be commit 594f84b4e39182dcf344c02dc0185376a2726395) --- source3/lib/iconv.c | 257 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 186 insertions(+), 71 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index b73ff6ff39..2285d8debf 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -21,13 +21,15 @@ #include "includes.h" -static size_t ascii_pull(char **, size_t *, char **, size_t *); -static size_t ascii_push(char **, size_t *, char **, size_t *); -static size_t utf8_pull(char **, size_t *, char **, size_t *); -static size_t utf8_push(char **, size_t *, char **, size_t *); -static size_t weird_pull(char **, size_t *, char **, size_t *); -static size_t weird_push(char **, size_t *, char **, size_t *); -static size_t iconv_copy(char **, size_t *, char **, size_t *); +static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); +static size_t ascii_push(void *,char **, size_t *, char **, size_t *); +static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); +static size_t utf8_push(void *,char **, size_t *, char **, size_t *); +static size_t weird_pull(void *,char **, size_t *, char **, size_t *); +static size_t weird_push(void *,char **, size_t *, char **, size_t *); +static size_t ucs2hex_pull(void *,char **, size_t *, char **, size_t *); +static size_t ucs2hex_push(void *,char **, size_t *, char **, size_t *); +static size_t iconv_copy(void *,char **, size_t *, char **, size_t *); /* for each charset we have a function that pulls from that charset to @@ -35,18 +37,39 @@ static size_t iconv_copy(char **, size_t *, char **, size_t *); */ static struct { char *name; - size_t (*pull)(char **inbuf, size_t *inbytesleft, + size_t (*pull)(void *, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); - size_t (*push)(char **inbuf, size_t *inbytesleft, + size_t (*push)(void *, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); } charsets[] = { {"UCS-2LE", iconv_copy, iconv_copy}, {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, {"WEIRD", weird_pull, weird_push}, + {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}, {NULL, NULL, NULL} }; + +/* if there was an error then reset the internal state, + this ensures that we don't have a shift state remaining for + character sets like SJIS */ +static size_t sys_iconv(void *cd, + char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ +#ifdef HAVE_NATIVE_ICONV + size_t ret = iconv((iconv_t)cd, + inbuf, inbytesleft, + outbuf, outbytesleft); + if (ret == (size_t)-1) iconv(cd, NULL, NULL, NULL, NULL); + return ret; +#else + errno = EINVAL; + return -1; +#endif +} + /* this is a simple portable iconv() implementaion. It only knows about a very small number of character sets - just enough that Samba works @@ -60,36 +83,28 @@ size_t smb_iconv(smb_iconv_t cd, char *bufp = cvtbuf; size_t bufsize; -#ifdef HAVE_NATIVE_ICONV - if (cd->cd) { - size_t ret; - ret = iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); - - /* if there was an error then reset the internal state, - this ensures that we don't have a shift state remaining for - character sets like SJIS */ - if (ret == (size_t)-1) { - iconv(cd->cd, NULL, NULL, NULL, NULL); - } - return ret; - } -#endif - - /* in most cases we can go direct */ + /* in many cases we can go direct */ if (cd->direct) { - return cd->direct(inbuf, inbytesleft, outbuf, outbytesleft); + return cd->direct(cd->cd_direct, + inbuf, inbytesleft, outbuf, outbytesleft); } + /* otherwise we have to do it chunks at a time */ while (*inbytesleft > 0) { bufp = cvtbuf; bufsize = sizeof(cvtbuf); - if (cd->pull(inbuf, inbytesleft, &bufp, &bufsize) == -1 && - errno != E2BIG) return -1; + + if (cd->pull(cd->cd_pull, + inbuf, inbytesleft, &bufp, &bufsize) == -1 + && errno != E2BIG) return -1; bufp = cvtbuf; bufsize = sizeof(cvtbuf) - bufsize; - if (cd->push(&bufp, &bufsize, outbuf, outbytesleft) == -1) return -1; + + if (cd->push(cd->cd_push, + &bufp, &bufsize, + outbuf, outbytesleft) == -1) return -1; } return 0; @@ -102,9 +117,19 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) { smb_iconv_t ret; int from, to; -#ifdef HAVE_NATIVE_ICONV - iconv_t cd = NULL; -#endif + + ret = (smb_iconv_t)malloc(sizeof(*ret)); + if (!ret) { + errno = ENOMEM; + return (smb_iconv_t)-1; + } + memset(ret, 0, sizeof(*ret)); + + /* check for the simplest null conversion */ + if (strcmp(fromcode, tocode) == 0) { + ret->direct = iconv_copy; + return ret; + } for (from=0; charsets[from].name; from++) { if (strcasecmp(charsets[from].name, fromcode) == 0) break; @@ -113,53 +138,57 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) if (strcasecmp(charsets[to].name, tocode) == 0) break; } - if (!charsets[from].name || !charsets[to].name) { #ifdef HAVE_NATIVE_ICONV - /* its not builtin - see if iconv() has it */ - cd = iconv_open(tocode, fromcode); - if (!cd) -#endif - { - errno = EINVAL; - return (smb_iconv_t)-1; - } + if (!charsets[from].name) { + ret->pull = sys_iconv; + ret->cd_pull = iconv_open("UCS-2LE", fromcode); + if (!ret->cd_pull) goto failed; } - - ret = (smb_iconv_t)malloc(sizeof(*ret)); - if (!ret) { - errno = ENOMEM; - return (smb_iconv_t)-1; + if (!charsets[to].name) { + ret->push = sys_iconv; + ret->cd_push = iconv_open(tocode, "UCS-2LE"); + if (!ret->cd_push) goto failed; } - memset(ret, 0, sizeof(*ret)); - -#ifdef HAVE_NATIVE_ICONV - /* see if we will be using the native iconv */ - if (cd) { - ret->cd = cd; - return ret; +#else + if (!charsets[from].name || !charsets[to].name) { + goto failed; } #endif - /* check for the simplest null conversion */ - if (from == to) { - ret->direct = iconv_copy; + /* check for conversion to/from ucs2 */ + if (from == 0 && charsets[to].name) { + ret->direct = charsets[to].push; + return ret; + } + if (to == 0 && charsets[from].name) { + ret->direct = charsets[from].pull; return ret; } - /* check for conversion to/from ucs2 */ +#ifdef HAVE_NATIVE_ICONV if (from == 0) { - ret->direct = charsets[to].push; + ret->direct = sys_iconv; + ret->cd_direct = ret->cd_push; + ret->cd_push = NULL; return ret; } if (to == 0) { - ret->direct = charsets[from].pull; + ret->direct = sys_iconv; + ret->cd_direct = ret->cd_pull; + ret->cd_pull = NULL; return ret; } +#endif /* the general case has to go via a buffer */ - ret->pull = charsets[from].pull; - ret->push = charsets[to].push; + if (!ret->pull) ret->pull = charsets[from].pull; + if (!ret->push) ret->push = charsets[to].push; return ret; + +failed: + free(ret); + errno = EINVAL; + return (smb_iconv_t)-1; } /* @@ -168,10 +197,11 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) int smb_iconv_close (smb_iconv_t cd) { #ifdef HAVE_NATIVE_ICONV - if (cd->cd) { - iconv_close(cd->cd); - } + if (cd->cd_direct) iconv_close((iconv_t)cd->cd_direct); + if (cd->cd_pull) iconv_close((iconv_t)cd->cd_pull); + if (cd->cd_push) iconv_close((iconv_t)cd->cd_push); #endif + memset(cd, 0, sizeof(*cd)); free(cd); return 0; @@ -184,7 +214,7 @@ int smb_iconv_close (smb_iconv_t cd) multi-byte character set support for english users ***********************************************************************/ -static size_t ascii_pull(char **inbuf, size_t *inbytesleft, +static size_t ascii_pull(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { @@ -204,7 +234,7 @@ static size_t ascii_pull(char **inbuf, size_t *inbytesleft, return 0; } -static size_t ascii_push(char **inbuf, size_t *inbytesleft, +static size_t ascii_push(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int ir_count=0; @@ -232,6 +262,91 @@ static size_t ascii_push(char **inbuf, size_t *inbytesleft, } +static size_t ucs2hex_pull(void *cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + unsigned v; + + if ((*inbuf)[0] != '@') { + /* seven bit ascii case */ + (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[1] = 0; + (*inbytesleft) -= 1; + (*outbytesleft) -= 2; + (*inbuf) += 1; + (*outbuf) += 2; + continue; + } + /* it's a hex character */ + if (*inbytesleft < 5) { + errno = EINVAL; + return -1; + } + + if (sscanf(&(*inbuf)[1], "%04x", &v) != 1) { + errno = EILSEQ; + return -1; + } + + (*outbuf)[0] = v&0xff; + (*outbuf)[1] = v>>8; + (*inbytesleft) -= 5; + (*outbytesleft) -= 2; + (*inbuf) += 5; + (*outbuf) += 2; + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + char buf[6]; + + if ((*inbuf)[1] == 0 && + ((*inbuf)[0] & 0x80) == 0 && + (*inbuf)[0] != '@') { + (*outbuf)[0] = (*inbuf)[0]; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + continue; + } + if (*outbytesleft < 5) { + errno = E2BIG; + return -1; + } + snprintf(buf, 6, "@%04x", SVAL(*inbuf, 0)); + memcpy(*outbuf, buf, 5); + (*inbytesleft) -= 2; + (*outbytesleft) -= 5; + (*inbuf) += 2; + (*outbuf) += 5; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return 0; +} + + /* the "weird" character set is very useful for testing multi-byte support and finding bugs. Don't use on a production system! */ @@ -245,7 +360,7 @@ static struct { {0, NULL} }; -static size_t weird_pull(char **inbuf, size_t *inbytesleft, +static size_t weird_pull(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { @@ -288,7 +403,7 @@ static size_t weird_pull(char **inbuf, size_t *inbytesleft, return 0; } -static size_t weird_push(char **inbuf, size_t *inbytesleft, +static size_t weird_push(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int ir_count=0; @@ -337,7 +452,7 @@ static size_t weird_push(char **inbuf, size_t *inbytesleft, return ir_count; } -static size_t iconv_copy(char **inbuf, size_t *inbytesleft, +static size_t iconv_copy(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int n; @@ -359,7 +474,7 @@ static size_t iconv_copy(char **inbuf, size_t *inbytesleft, return 0; } -static size_t utf8_pull(char **inbuf, size_t *inbytesleft, +static size_t utf8_pull(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { @@ -406,7 +521,7 @@ badseq: return -1; } -static size_t utf8_push(char **inbuf, size_t *inbytesleft, +static size_t utf8_push(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 2 && *outbytesleft >= 1) { -- cgit From 5573a1c7394362f5e46c58b8cfaf6bf7a080c391 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Sep 2001 14:14:57 +0000 Subject: added "display charset" option in smb.conf, along with d_printf() which should now be used instead of DEBUG(0) or printf() for interactive messages I have only converted client.c to use d_printf(), and the code hasn't had much testing yet. Eventually we want all interactive code to use d_printf(), plus SWAT (This used to be commit 266d8e67669adb329f25676c4bc4d4c50f223428) --- source3/lib/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 2285d8debf..46507dd624 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -142,12 +142,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) if (!charsets[from].name) { ret->pull = sys_iconv; ret->cd_pull = iconv_open("UCS-2LE", fromcode); - if (!ret->cd_pull) goto failed; + if (ret->cd_pull == (iconv_t)-1) goto failed; } if (!charsets[to].name) { ret->push = sys_iconv; ret->cd_push = iconv_open(tocode, "UCS-2LE"); - if (!ret->cd_push) goto failed; + if (ret->cd_push == (iconv_t)-1) goto failed; } #else if (!charsets[from].name || !charsets[to].name) { -- cgit From 484a7c0341fe033fe26fe1e6b597ed1c456c39d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 02:19:44 +0000 Subject: move to SAFE_FREE() (This used to be commit 60e907b7e8e1c008463a88ed2b076344278986ef) --- source3/lib/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 46507dd624..a8962726e0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -186,7 +186,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) return ret; failed: - free(ret); + SAFE_FREE(ret); errno = EINVAL; return (smb_iconv_t)-1; } @@ -203,7 +203,7 @@ int smb_iconv_close (smb_iconv_t cd) #endif memset(cd, 0, sizeof(*cd)); - free(cd); + SAFE_FREE(cd); return 0; } -- cgit From c386d8bdd0fc4e29be2e7acc61e5ee84fd52d1f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Sep 2001 04:27:59 +0000 Subject: allow all ucs2 chars in utf8, rather than mapping some to a single char like libiconv does (This used to be commit e13e8b190c70136cb2c3588bdcf7328a7f61d152) --- source3/lib/iconv.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index a8962726e0..05292264c2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -529,16 +529,7 @@ static size_t utf8_push(void *cd, char **inbuf, size_t *inbytesleft, unsigned char *uc = (unsigned char *)*inbuf; int len=1; - if ((uc[1] & 0xf8) == 0xd8) { - if (*outbytesleft < 3) { - DEBUG(0,("short utf8 write\n")); - goto toobig; - } - c[0] = 0xed; - c[1] = 0x9f; - c[2] = 0xbf; - len = 3; - } else if (uc[1] & 0xf8) { + if (uc[1] & 0xf8) { if (*outbytesleft < 3) { DEBUG(0,("short utf8 write\n")); goto toobig; -- cgit From d25c2b146b1581ef2a141ecbc04579b792b4c4dc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Sep 2001 11:51:40 +0000 Subject: Add a few const statements to various odd bits of the tree. (Fixes some warnings) (This used to be commit b648cc669d16eb40b477c8dc51efeab485a15de5) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 05292264c2..cf9fabf8c6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -76,7 +76,7 @@ static size_t sys_iconv(void *cd, on systems that don't have iconv */ size_t smb_iconv(smb_iconv_t cd, - char **inbuf, size_t *inbytesleft, + const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { char cvtbuf[2048]; -- cgit From 3ea349271355b39f7b877ce67530cc58e7db0ee8 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 23 Oct 2001 19:10:30 +0000 Subject: get rid of compiler warnings (casts and delete unused variables) (This used to be commit 51cb4411df61d1caec9d84809b1a53a6a632f808) --- source3/lib/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index cf9fabf8c6..8bcd92d72a 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -86,7 +86,7 @@ size_t smb_iconv(smb_iconv_t cd, /* in many cases we can go direct */ if (cd->direct) { return cd->direct(cd->cd_direct, - inbuf, inbytesleft, outbuf, outbytesleft); + (char **)inbuf, inbytesleft, outbuf, outbytesleft); } @@ -96,7 +96,7 @@ size_t smb_iconv(smb_iconv_t cd, bufsize = sizeof(cvtbuf); if (cd->pull(cd->cd_pull, - inbuf, inbytesleft, &bufp, &bufsize) == -1 + (char **)inbuf, inbytesleft, &bufp, &bufsize) == -1 && errno != E2BIG) return -1; bufp = cvtbuf; -- cgit From ec312741639c447c83ad76683c9f1538a3f5084b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 Dec 2001 06:18:52 +0000 Subject: much better auto-init of valid_table[]. This should just about remove the need for valid.dat (This used to be commit 0cfd0a5e543181b1384f7afee93fbaf3ccb2b999) --- source3/lib/iconv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 8bcd92d72a..c08524eaa0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -125,6 +125,9 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } memset(ret, 0, sizeof(*ret)); + ret->from_name = strdup(fromcode); + ret->to_name = strdup(tocode); + /* check for the simplest null conversion */ if (strcmp(fromcode, tocode) == 0) { ret->direct = iconv_copy; @@ -202,6 +205,9 @@ int smb_iconv_close (smb_iconv_t cd) if (cd->cd_push) iconv_close((iconv_t)cd->cd_push); #endif + SAFE_FREE(cd->from_name); + SAFE_FREE(cd->to_name); + memset(cd, 0, sizeof(*cd)); SAFE_FREE(cd); return 0; @@ -240,7 +246,7 @@ static size_t ascii_push(void *cd, char **inbuf, size_t *inbytesleft, int ir_count=0; while (*inbytesleft >= 2 && *outbytesleft >= 1) { - (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[0] = (*inbuf)[0] & 0x7F; if ((*inbuf)[1]) ir_count++; (*inbytesleft) -= 2; (*outbytesleft) -= 1; -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/lib/iconv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index c08524eaa0..43350d9349 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. minimal iconv implementation Copyright (C) Andrew Tridgell 2001 -- cgit From ff5d95f0efa6370d4aa747e28ba8e5cac489dc44 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 27 Feb 2003 05:57:21 +0000 Subject: Doxygen merge from head (This used to be commit 38fa2898967f607a17fd7fbd324f2940a05fb551) --- source3/lib/iconv.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 43350d9349..e4845e4734 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -69,11 +69,12 @@ static size_t sys_iconv(void *cd, #endif } -/* - this is a simple portable iconv() implementaion. It only knows about - a very small number of character sets - just enough that Samba works - on systems that don't have iconv - */ +/** + * This is a simple portable iconv() implementaion. + * + * It only knows about a very small number of character sets - just + * enough that Samba works on systems that don't have iconv. + **/ size_t smb_iconv(smb_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) -- cgit From e9f51a6e38eb270c0d3643292978410e048ca173 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Mar 2003 19:37:31 +0000 Subject: Patch from Michael Steffens. In his own words : ------------------------------------------------------------------------- I think there are basically two problem: 1. Windows clients do not always send ACEs for SMB_ACL_USER_OBJ, SMB_ACL_GROUP_OBJ, and SMB_ACL_OTHER. The function ensure_canon_entry_valid() is prepared for that, but tries to "guess" values from group or other permissions, respectively, otherwise falling back to minimum r-- for the owner. Even if the owner had full permissions before setting ACL. This is the problem with W2k clients. 2. Function set_nt_acl() always chowns *before* attempting to set POSIX ACLs. This is ok in a take-ownership situation, but must fail if the file is to be given away. This is the problem with XP clients, trying to transfer ownership of the original file to the temp file. The problem with NT4 clients (no ACEs are transferred to the temp file, thus are lost after moving the temp file to the original name) is a client problem. It simply doesn't attempt to. I have played around with that using posic_acls.c from 3.0 merged into 2.2. As a result I can now present two patches, one for each branch. They basically modify: 1. Interpret missing SMB_ACL_USER_OBJ, SMB_ACL_GROUP_OBJ, or SMB_ACL_OTHER as "preserve current value" instead of attempting to build one ourself. The original code is still in, but only as fallback in case current values can't be retrieved. 2. Rearrange set_nt_acl() such that chown is only done before setting ACLs if there is either no change of owning user, or change of owning user is towards the current user. Otherwise chown is done after setting ACLs. It now seems to produce reasonable results. (Well, as far as it can. If NT4 doesn't even try to transfer ACEs, only deliberate use of named default ACEs and/or "force group" or the crystal ball can help :) ------------------------------------------------------------------------- Jeremy. (This used to be commit 1d3b8c528bebfa1971d1affe454a03453335786e) --- source3/lib/iconv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index e4845e4734..54733c2ac2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -35,7 +35,7 @@ static size_t iconv_copy(void *,char **, size_t *, char **, size_t *); a ucs2 buffer, and a function that pushes to a ucs2 buffer */ static struct { - char *name; + const char *name; size_t (*pull)(void *, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); size_t (*push)(void *, char **inbuf, size_t *inbytesleft, @@ -357,8 +357,8 @@ static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft, support and finding bugs. Don't use on a production system! */ static struct { - char from; - char *to; + const char from; + const char *to; int len; } weird_table[] = { {'q', "^q^", 3}, -- cgit From 004502551bd53ae68a7dfee8bdb47831c9c39817 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Apr 2003 13:09:00 +0000 Subject: Add support for the new modules system to lib/iconv.c (merge from HEAD) (This used to be commit 64a357017a897d1920c06fc19453470ee517470d) --- source3/lib/iconv.c | 281 ++++++++++++++++++++++++---------------------------- 1 file changed, 130 insertions(+), 151 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 54733c2ac2..d161975601 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. minimal iconv implementation Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2002,2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,35 +21,97 @@ #include "includes.h" + +/** + * @file + * + * @brief Samba wrapper/stub for iconv character set conversion. + * + * iconv is the XPG2 interface for converting between character + * encodings. This file provides a Samba wrapper around it, and also + * a simple reimplementation that is used if the system does not + * implement iconv. + * + * Samba only works with encodings that are supersets of ASCII: ascii + * characters like whitespace can be tested for directly, multibyte + * sequences start with a byte with the high bit set, and strings are + * terminated by a nul byte. + * + * Note that the only function provided by iconv is conversion between + * characters. It doesn't directly support operations like + * uppercasing or comparison. We have to convert to UCS-2 and compare + * there. + * + * @sa Samba Developers Guide + **/ + static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); static size_t ascii_push(void *,char **, size_t *, char **, size_t *); static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); static size_t utf8_push(void *,char **, size_t *, char **, size_t *); -static size_t weird_pull(void *,char **, size_t *, char **, size_t *); -static size_t weird_push(void *,char **, size_t *, char **, size_t *); static size_t ucs2hex_pull(void *,char **, size_t *, char **, size_t *); static size_t ucs2hex_push(void *,char **, size_t *, char **, size_t *); static size_t iconv_copy(void *,char **, size_t *, char **, size_t *); -/* - for each charset we have a function that pulls from that charset to - a ucs2 buffer, and a function that pushes to a ucs2 buffer -*/ -static struct { - const char *name; - size_t (*pull)(void *, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft); - size_t (*push)(void *, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft); -} charsets[] = { +static struct charset_functions builtin_functions[] = { {"UCS-2LE", iconv_copy, iconv_copy}, {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, - {"WEIRD", weird_pull, weird_push}, {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}, {NULL, NULL, NULL} }; +static struct charset_functions *charsets = NULL; + +static struct charset_functions *find_charset_functions(const char *name) +{ + struct charset_functions *c = charsets; + pstring stripped; + + module_path_get_name(name, stripped); + + while(c) { + if (strcasecmp(stripped, c->name) == 0) { + return c; + } + c = c->next; + } + + return NULL; +} + +BOOL smb_register_charset(struct charset_functions *funcs) +{ + struct charset_functions *c = charsets; + + DEBUG(5, ("Attempting to register new charset %s\n", funcs->name)); + /* Check whether we already have this charset... */ + while(c) { + if(!strcasecmp(c->name, funcs->name)){ + DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); + return False; + } + c = c->next; + } + + funcs->next = funcs->prev = NULL; + DEBUG(5, ("Registered charset %s\n", funcs->name)); + DLIST_ADD(charsets, funcs); + return True; +} + +void lazy_initialize_iconv(void) +{ + static BOOL initialized; + int i; + + if (!initialized) { + initialized = True; + for(i = 0; builtin_functions[i].name; i++) + smb_register_charset(&builtin_functions[i]); + static_init_charset; + } +} /* if there was an error then reset the internal state, this ensures that we don't have a shift state remaining for @@ -116,7 +179,11 @@ size_t smb_iconv(smb_iconv_t cd, smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) { smb_iconv_t ret; - int from, to; + struct charset_functions *from, *to; + + lazy_initialize_iconv(); + from = charsets; + to = charsets; ret = (smb_iconv_t)malloc(sizeof(*ret)); if (!ret) { @@ -129,53 +196,78 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) ret->to_name = strdup(tocode); /* check for the simplest null conversion */ - if (strcmp(fromcode, tocode) == 0) { + if (strcasecmp(fromcode, tocode) == 0) { ret->direct = iconv_copy; return ret; } - for (from=0; charsets[from].name; from++) { - if (strcasecmp(charsets[from].name, fromcode) == 0) break; - } - for (to=0; charsets[to].name; to++) { - if (strcasecmp(charsets[to].name, tocode) == 0) break; - } + /* check if we have a builtin function for this conversion */ + from = find_charset_functions(fromcode); + if(from)ret->pull = from->pull; + + to = find_charset_functions(tocode); + if(to)ret->push = to->push; + /* check if we can use iconv for this conversion */ #ifdef HAVE_NATIVE_ICONV - if (!charsets[from].name) { - ret->pull = sys_iconv; + if (!ret->pull) { ret->cd_pull = iconv_open("UCS-2LE", fromcode); - if (ret->cd_pull == (iconv_t)-1) goto failed; + if (ret->cd_pull != (iconv_t)-1) + ret->pull = sys_iconv; } - if (!charsets[to].name) { - ret->push = sys_iconv; + + if (!ret->push) { ret->cd_push = iconv_open(tocode, "UCS-2LE"); - if (ret->cd_push == (iconv_t)-1) goto failed; - } -#else - if (!charsets[from].name || !charsets[to].name) { - goto failed; + if (ret->cd_push != (iconv_t)-1) + ret->push = sys_iconv; } #endif + + /* check if there is a module available that can do this conversion */ + if (!ret->pull && smb_probe_module("charset", fromcode)) { + if(!(from = find_charset_functions(fromcode))) + DEBUG(0, ("Module %s doesn't provide charset %s!\n", fromcode, fromcode)); + else + ret->pull = from->pull; + } + + if (!ret->push && smb_probe_module("charset", tocode)) { + if(!(to = find_charset_functions(tocode))) + DEBUG(0, ("Module %s doesn't provide charset %s!\n", tocode, tocode)); + else + ret->push = to->push; + } + + if (!ret->push || !ret->pull) { + SAFE_FREE(ret->from_name); + SAFE_FREE(ret->to_name); + SAFE_FREE(ret); + errno = EINVAL; + return (smb_iconv_t)-1; + } /* check for conversion to/from ucs2 */ - if (from == 0 && charsets[to].name) { - ret->direct = charsets[to].push; + if (strcasecmp(fromcode, "UCS-2LE") == 0 && to) { + ret->direct = to->push; + ret->push = ret->pull = NULL; return ret; } - if (to == 0 && charsets[from].name) { - ret->direct = charsets[from].pull; + + if (strcasecmp(tocode, "UCS-2LE") == 0 && from) { + ret->direct = from->pull; + ret->push = ret->pull = NULL; return ret; } + /* Check if we can do the conversion direct */ #ifdef HAVE_NATIVE_ICONV - if (from == 0) { + if (strcasecmp(fromcode, "UCS-2LE") == 0) { ret->direct = sys_iconv; ret->cd_direct = ret->cd_push; ret->cd_push = NULL; return ret; } - if (to == 0) { + if (strcasecmp(tocode, "UCS-2LE") == 0) { ret->direct = sys_iconv; ret->cd_direct = ret->cd_pull; ret->cd_pull = NULL; @@ -183,15 +275,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } #endif - /* the general case has to go via a buffer */ - if (!ret->pull) ret->pull = charsets[from].pull; - if (!ret->push) ret->push = charsets[to].push; return ret; - -failed: - SAFE_FREE(ret); - errno = EINVAL; - return (smb_iconv_t)-1; } /* @@ -353,111 +437,6 @@ static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft, } -/* the "weird" character set is very useful for testing multi-byte - support and finding bugs. Don't use on a production system! -*/ -static struct { - const char from; - const char *to; - int len; -} weird_table[] = { - {'q', "^q^", 3}, - {'Q', "^Q^", 3}, - {0, NULL} -}; - -static size_t weird_pull(void *cd, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - while (*inbytesleft >= 1 && *outbytesleft >= 2) { - int i; - int done = 0; - for (i=0;weird_table[i].from;i++) { - if (strncmp((*inbuf), - weird_table[i].to, - weird_table[i].len) == 0) { - if (*inbytesleft < weird_table[i].len) { - DEBUG(0,("ERROR: truncated weird string\n")); - /* smb_panic("weird_pull"); */ - - } else { - (*outbuf)[0] = weird_table[i].from; - (*outbuf)[1] = 0; - (*inbytesleft) -= weird_table[i].len; - (*outbytesleft) -= 2; - (*inbuf) += weird_table[i].len; - (*outbuf) += 2; - done = 1; - break; - } - } - } - if (done) continue; - (*outbuf)[0] = (*inbuf)[0]; - (*outbuf)[1] = 0; - (*inbytesleft) -= 1; - (*outbytesleft) -= 2; - (*inbuf) += 1; - (*outbuf) += 2; - } - - if (*inbytesleft > 0) { - errno = E2BIG; - return -1; - } - - return 0; -} - -static size_t weird_push(void *cd, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - int ir_count=0; - - while (*inbytesleft >= 2 && *outbytesleft >= 1) { - int i; - int done=0; - for (i=0;weird_table[i].from;i++) { - if ((*inbuf)[0] == weird_table[i].from && - (*inbuf)[1] == 0) { - if (*outbytesleft < weird_table[i].len) { - DEBUG(0,("No room for weird character\n")); - /* smb_panic("weird_push"); */ - } else { - memcpy(*outbuf, weird_table[i].to, - weird_table[i].len); - (*inbytesleft) -= 2; - (*outbytesleft) -= weird_table[i].len; - (*inbuf) += 2; - (*outbuf) += weird_table[i].len; - done = 1; - break; - } - } - } - if (done) continue; - - (*outbuf)[0] = (*inbuf)[0]; - if ((*inbuf)[1]) ir_count++; - (*inbytesleft) -= 2; - (*outbytesleft) -= 1; - (*inbuf) += 2; - (*outbuf) += 1; - } - - if (*inbytesleft == 1) { - errno = EINVAL; - return -1; - } - - if (*inbytesleft > 1) { - errno = E2BIG; - return -1; - } - - return ir_count; -} - static size_t iconv_copy(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { -- cgit From 08b30fcf2701a7eb75e75a922cc7f8da601450e7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 24 Apr 2003 20:27:19 +0000 Subject: Get rid of module_path_get_name() and use the find backend function to find duplicates (This used to be commit 871cad7e9ac38e6f8e4391fcb2894d91300cbe94) --- source3/lib/iconv.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index d161975601..01fa31915a 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -66,12 +66,9 @@ static struct charset_functions *charsets = NULL; static struct charset_functions *find_charset_functions(const char *name) { struct charset_functions *c = charsets; - pstring stripped; - module_path_get_name(name, stripped); - while(c) { - if (strcasecmp(stripped, c->name) == 0) { + if (strcasecmp(name, c->name) == 0) { return c; } c = c->next; @@ -86,12 +83,10 @@ BOOL smb_register_charset(struct charset_functions *funcs) DEBUG(5, ("Attempting to register new charset %s\n", funcs->name)); /* Check whether we already have this charset... */ - while(c) { - if(!strcasecmp(c->name, funcs->name)){ - DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); - return False; - } - c = c->next; + + if (find_charset_functions(funcs->name)) { + DEBUG(0, ("Duplicate charset %s, not registering\n", funcs->name)); + return False; } funcs->next = funcs->prev = NULL; -- cgit From 17a3acafa89bfc6090b0767d05a00a7505003fcc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Apr 2003 17:48:48 +0000 Subject: Use NTSTATUS as return value for smb_register_*() functions and init_module() function. Patch by metze with some minor modifications. (This used to be commit bc4b51bcb2daa7271c884cb83bf8bdba6d3a9b6d) --- source3/lib/iconv.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 01fa31915a..c09bff5fd7 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -77,22 +77,23 @@ static struct charset_functions *find_charset_functions(const char *name) return NULL; } -BOOL smb_register_charset(struct charset_functions *funcs) +NTSTATUS smb_register_charset(struct charset_functions *funcs) { - struct charset_functions *c = charsets; + if (!funcs) { + return NT_STATUS_INVALID_PARAMETER; + } DEBUG(5, ("Attempting to register new charset %s\n", funcs->name)); /* Check whether we already have this charset... */ - if (find_charset_functions(funcs->name)) { DEBUG(0, ("Duplicate charset %s, not registering\n", funcs->name)); - return False; + return NT_STATUS_OBJECT_NAME_COLLISION; } funcs->next = funcs->prev = NULL; DEBUG(5, ("Registered charset %s\n", funcs->name)); DLIST_ADD(charsets, funcs); - return True; + return NT_STATUS_OK; } void lazy_initialize_iconv(void) @@ -219,14 +220,14 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) #endif /* check if there is a module available that can do this conversion */ - if (!ret->pull && smb_probe_module("charset", fromcode)) { + if (!ret->pull && NT_STATUS_IS_OK(smb_probe_module("charset", fromcode))) { if(!(from = find_charset_functions(fromcode))) DEBUG(0, ("Module %s doesn't provide charset %s!\n", fromcode, fromcode)); else ret->pull = from->pull; } - if (!ret->push && smb_probe_module("charset", tocode)) { + if (!ret->push && NT_STATUS_IS_OK(smb_probe_module("charset", tocode))) { if(!(to = find_charset_functions(tocode))) DEBUG(0, ("Module %s doesn't provide charset %s!\n", tocode, tocode)); else -- cgit From ce12b32c4a502cc5df58f2b46d54370cdf3b673e Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Sun, 13 Jul 2003 16:25:55 +0000 Subject: Fix compiler warning. (This used to be commit 3a71b4873034b3fe9dc7b23a95e56c865e857507) --- source3/lib/iconv.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index c09bff5fd7..e3866c2b53 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -135,17 +135,22 @@ static size_t sys_iconv(void *cd, * enough that Samba works on systems that don't have iconv. **/ size_t smb_iconv(smb_iconv_t cd, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) + const char **inbuffer, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) { char cvtbuf[2048]; char *bufp = cvtbuf; size_t bufsize; + /* make a copy to ensure inbuffer is const-ed */ + char* inbuf = smb_xstrdup(*inbuffer); + size_t result; /* in many cases we can go direct */ if (cd->direct) { - return cd->direct(cd->cd_direct, - (char **)inbuf, inbytesleft, outbuf, outbytesleft); + result = cd->direct(cd->cd_direct, + &inbuf, inbytesleft, outbuf, outbytesleft); + SAFE_FREE(inbuf); + return result; } @@ -154,18 +159,23 @@ size_t smb_iconv(smb_iconv_t cd, bufp = cvtbuf; bufsize = sizeof(cvtbuf); - if (cd->pull(cd->cd_pull, - (char **)inbuf, inbytesleft, &bufp, &bufsize) == -1 - && errno != E2BIG) return -1; + if (cd->pull(cd->cd_pull, + &inbuf, inbytesleft, &bufp, &bufsize) == -1 && errno != E2BIG) { + SAFE_FREE(inbuf); + return -1; + } bufp = cvtbuf; bufsize = sizeof(cvtbuf) - bufsize; - if (cd->push(cd->cd_push, - &bufp, &bufsize, - outbuf, outbytesleft) == -1) return -1; + if (cd->push(cd->cd_push, + &bufp, &bufsize, outbuf, outbytesleft) == -1) { + SAFE_FREE(inbuf); + return -1; + } } - + + SAFE_FREE(inbuf); return 0; } -- cgit From 4b25a466242bf009a7b97df795cf2e5d6a249da5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Jul 2003 01:18:43 +0000 Subject: Undo 'Fix compiler warning'. It didn't work because the value of inbuf changes so we end up freeing a pointer we didn't mallocate. Also, calling strdup() in a frequently called function just to clear up a const compiler warning seems inelegant and inefficient. (This used to be commit a0da5ae1198082d0cf18707ed2cf05f728b00d0b) --- source3/lib/iconv.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index e3866c2b53..c09bff5fd7 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -135,22 +135,17 @@ static size_t sys_iconv(void *cd, * enough that Samba works on systems that don't have iconv. **/ size_t smb_iconv(smb_iconv_t cd, - const char **inbuffer, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) { char cvtbuf[2048]; char *bufp = cvtbuf; size_t bufsize; - /* make a copy to ensure inbuffer is const-ed */ - char* inbuf = smb_xstrdup(*inbuffer); - size_t result; /* in many cases we can go direct */ if (cd->direct) { - result = cd->direct(cd->cd_direct, - &inbuf, inbytesleft, outbuf, outbytesleft); - SAFE_FREE(inbuf); - return result; + return cd->direct(cd->cd_direct, + (char **)inbuf, inbytesleft, outbuf, outbytesleft); } @@ -159,23 +154,18 @@ size_t smb_iconv(smb_iconv_t cd, bufp = cvtbuf; bufsize = sizeof(cvtbuf); - if (cd->pull(cd->cd_pull, - &inbuf, inbytesleft, &bufp, &bufsize) == -1 && errno != E2BIG) { - SAFE_FREE(inbuf); - return -1; - } + if (cd->pull(cd->cd_pull, + (char **)inbuf, inbytesleft, &bufp, &bufsize) == -1 + && errno != E2BIG) return -1; bufp = cvtbuf; bufsize = sizeof(cvtbuf) - bufsize; - if (cd->push(cd->cd_push, - &bufp, &bufsize, outbuf, outbytesleft) == -1) { - SAFE_FREE(inbuf); - return -1; - } + if (cd->push(cd->cd_push, + &bufp, &bufsize, + outbuf, outbytesleft) == -1) return -1; } - - SAFE_FREE(inbuf); + return 0; } -- cgit From f9b6d0fd108de242e0cb93218a8a344f927899c0 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Mon, 15 Sep 2003 12:42:10 +0000 Subject: Alias charset 646 internally as it is same as ASCII. Should solve Solaris problems where ASCII was not detected and 646.so were requested through dynamic loading (This used to be commit c248cd4784ac0f8f16813de36d293ab6bf1d259b) --- source3/lib/iconv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index c09bff5fd7..3d26d7e17c 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -57,6 +57,7 @@ static struct charset_functions builtin_functions[] = { {"UCS-2LE", iconv_copy, iconv_copy}, {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, + {"646", ascii_pull, ascii_push}, {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}, {NULL, NULL, NULL} }; -- cgit From fa7932296d65be2ffd0cd63a034e2c020ceaa8c5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 27 Sep 2003 01:29:18 +0000 Subject: iconv isn't const safe. Neither should smb_iconv be. Jeremy. (This used to be commit 238bb74c16417140d85a304890b97e04df389ae9) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 3d26d7e17c..0326ca7061 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -136,7 +136,7 @@ static size_t sys_iconv(void *cd, * enough that Samba works on systems that don't have iconv. **/ size_t smb_iconv(smb_iconv_t cd, - const char **inbuf, size_t *inbytesleft, + char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { char cvtbuf[2048]; -- cgit From bb0598faf58679a7ad26a1caab8eadb154a07ae2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Oct 2003 23:38:20 +0000 Subject: Put strcasecmp/strncasecmp on the banned list (except for needed calls in iconv.c and nsswitch/). Using them means you're not thinking about multibyte at all and I really want to discourage that. Jeremy. (This used to be commit d7e35dfb9283d560d0ed2ab231f36ed92767dace) --- source3/lib/iconv.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 0326ca7061..9f6db79ee2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -21,6 +21,12 @@ #include "includes.h" +/* + * We have to use strcasecmp here as the character conversions + * haven't been initialised yet. JRA. + */ + +#undef strcasecmp /** * @file -- cgit From 57607049187fc735d16050cb6f5d1aa41cf44747 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Wed, 10 Dec 2003 15:59:28 +0000 Subject: Fix #558 -- support ISO-8859-1 internally. Makes Solaris users a bit happier (This used to be commit ba95fe56d2db8243191d5dd6b75c6b65e0f5fbe9) --- source3/lib/iconv.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 9f6db79ee2..b0c13a5ee6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -53,6 +53,7 @@ static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); static size_t ascii_push(void *,char **, size_t *, char **, size_t *); +static size_t latin1_push(void *,char **, size_t *, char **, size_t *); static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); static size_t utf8_push(void *,char **, size_t *, char **, size_t *); static size_t ucs2hex_pull(void *,char **, size_t *, char **, size_t *); @@ -64,6 +65,7 @@ static struct charset_functions builtin_functions[] = { {"UTF8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, {"646", ascii_pull, ascii_push}, + {"ISO-8859-1", ascii_pull, latin1_push}, {"UCS2-HEX", ucs2hex_pull, ucs2hex_push}, {NULL, NULL, NULL} }; @@ -354,6 +356,32 @@ static size_t ascii_push(void *cd, char **inbuf, size_t *inbytesleft, return ir_count; } +static size_t latin1_push(void *cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int ir_count=0; + + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + (*outbuf)[0] = (*inbuf)[0]; + if ((*inbuf)[1]) ir_count++; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return ir_count; +} static size_t ucs2hex_pull(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) -- cgit From 39f8afa866b6a29b3fd96c7bbadc1456ab40c548 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Feb 2004 02:09:41 +0000 Subject: Working on #830. Cope with bad conversions better - don't just memcpy but try a crap conversion instead. Next this needs to be done to the convert_alloc function. Actually fixes some valgrind warnings as well - cool ! Jeremy. (This used to be commit 6a7919f2544a689840fe46f3c58ed66f69aca65a) --- source3/lib/iconv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index b0c13a5ee6..d0d2dcd1c4 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -589,4 +589,3 @@ toobig: errno = E2BIG; return -1; } - -- cgit From d198c5587774808823aa09e997ff492826738c51 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 8 Feb 2004 08:38:42 +0000 Subject: Make more functions static, and remove duplication in the use of functions in lib/smbpasswd.c that were exact duplicates of functions in passdb/passdb.c (These should perhaps be pulled back out to smbpasswd.c, but that can occour later). Andrew Bartlett (This used to be commit fcdc5efb1e245c8fa95cd031f67ec56093b9056e) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index d0d2dcd1c4..7df73192f2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -105,7 +105,7 @@ NTSTATUS smb_register_charset(struct charset_functions *funcs) return NT_STATUS_OK; } -void lazy_initialize_iconv(void) +static void lazy_initialize_iconv(void) { static BOOL initialized; int i; -- cgit From 81c497b38b33f6917e2f46182c26b1ff0fcbae7d Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 28 May 2004 17:57:18 +0000 Subject: r938: on an error save the original errno before calling iconv to reset the conversion state (This used to be commit 4a5a122b3a85c653bbf458342400f3b8a69dc615) --- source3/lib/iconv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 7df73192f2..4c9ecf992e 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -129,7 +129,11 @@ static size_t sys_iconv(void *cd, size_t ret = iconv((iconv_t)cd, inbuf, inbytesleft, outbuf, outbytesleft); - if (ret == (size_t)-1) iconv(cd, NULL, NULL, NULL, NULL); + if (ret == (size_t)-1) { + int saved_errno = errno; + iconv(cd, NULL, NULL, NULL, NULL); + errno = saved_errno; + } return ret; #else errno = EINVAL; -- cgit From 651daa4b4256455b26b0affcdc45fe328b128c99 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Aug 2004 21:35:43 +0000 Subject: r2114: Shameless theft of iconv commit from Samba4 to keep the two libs more in sync :-). try to cope with a wider range of UTF-16 characters when we are using an external libiconv library. Jeremy. (This used to be commit 5d04cd6804f6fc3b556e7c3b53fa0d7af39797c1) --- source3/lib/iconv.c | 79 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 24 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 4c9ecf992e..e10e42328c 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -51,18 +51,25 @@ * @sa Samba Developers Guide **/ -static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); -static size_t ascii_push(void *,char **, size_t *, char **, size_t *); -static size_t latin1_push(void *,char **, size_t *, char **, size_t *); -static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); -static size_t utf8_push(void *,char **, size_t *, char **, size_t *); -static size_t ucs2hex_pull(void *,char **, size_t *, char **, size_t *); -static size_t ucs2hex_push(void *,char **, size_t *, char **, size_t *); -static size_t iconv_copy(void *,char **, size_t *, char **, size_t *); +static size_t ascii_pull(void *,const char **, size_t *, char **, size_t *); +static size_t ascii_push(void *,const char **, size_t *, char **, size_t *); +static size_t latin1_push(void *,const char **, size_t *, char **, size_t *); +static size_t utf8_pull(void *,const char **, size_t *, char **, size_t *); +static size_t utf8_push(void *,const char **, size_t *, char **, size_t *); +static size_t ucs2hex_pull(void *,const char **, size_t *, char **, size_t *); +static size_t ucs2hex_push(void *,const char **, size_t *, char **, size_t *); +static size_t iconv_copy(void *,const char **, size_t *, char **, size_t *); +static size_t iconv_swab (void *,const char **, size_t *, char **, size_t *); static struct charset_functions builtin_functions[] = { + /* windows is really neither UCS-2 not UTF-16 */ {"UCS-2LE", iconv_copy, iconv_copy}, + {"UTF-16LE", iconv_copy, iconv_copy}, + {"UCS-2BE", iconv_swab, iconv_swab}, + + /* we include the UTF-8 alias to cope with differing locale settings */ {"UTF8", utf8_pull, utf8_push}, + {"UTF-8", utf8_pull, utf8_push}, {"ASCII", ascii_pull, ascii_push}, {"646", ascii_pull, ascii_push}, {"ISO-8859-1", ascii_pull, latin1_push}, @@ -122,12 +129,12 @@ static void lazy_initialize_iconv(void) this ensures that we don't have a shift state remaining for character sets like SJIS */ static size_t sys_iconv(void *cd, - char **inbuf, size_t *inbytesleft, + const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { #ifdef HAVE_NATIVE_ICONV size_t ret = iconv((iconv_t)cd, - inbuf, inbytesleft, + (char **)inbuf, inbytesleft, outbuf, outbytesleft); if (ret == (size_t)-1) { int saved_errno = errno; @@ -148,7 +155,7 @@ static size_t sys_iconv(void *cd, * enough that Samba works on systems that don't have iconv. **/ size_t smb_iconv(smb_iconv_t cd, - char **inbuf, size_t *inbytesleft, + const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { char cvtbuf[2048]; @@ -158,7 +165,7 @@ size_t smb_iconv(smb_iconv_t cd, /* in many cases we can go direct */ if (cd->direct) { return cd->direct(cd->cd_direct, - (char **)inbuf, inbytesleft, outbuf, outbytesleft); + inbuf, inbytesleft, outbuf, outbytesleft); } @@ -168,14 +175,14 @@ size_t smb_iconv(smb_iconv_t cd, bufsize = sizeof(cvtbuf); if (cd->pull(cd->cd_pull, - (char **)inbuf, inbytesleft, &bufp, &bufsize) == -1 + inbuf, inbytesleft, &bufp, &bufsize) == -1 && errno != E2BIG) return -1; bufp = cvtbuf; bufsize = sizeof(cvtbuf) - bufsize; if (cd->push(cd->cd_push, - &bufp, &bufsize, + (const char **)&bufp, &bufsize, outbuf, outbytesleft) == -1) return -1; } @@ -313,7 +320,7 @@ int smb_iconv_close (smb_iconv_t cd) multi-byte character set support for english users ***********************************************************************/ -static size_t ascii_pull(void *cd, char **inbuf, size_t *inbytesleft, +static size_t ascii_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { @@ -333,7 +340,7 @@ static size_t ascii_pull(void *cd, char **inbuf, size_t *inbytesleft, return 0; } -static size_t ascii_push(void *cd, char **inbuf, size_t *inbytesleft, +static size_t ascii_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int ir_count=0; @@ -360,7 +367,7 @@ static size_t ascii_push(void *cd, char **inbuf, size_t *inbytesleft, return ir_count; } -static size_t latin1_push(void *cd, char **inbuf, size_t *inbytesleft, +static size_t latin1_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int ir_count=0; @@ -387,7 +394,7 @@ static size_t latin1_push(void *cd, char **inbuf, size_t *inbytesleft, return ir_count; } -static size_t ucs2hex_pull(void *cd, char **inbuf, size_t *inbytesleft, +static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { @@ -430,7 +437,7 @@ static size_t ucs2hex_pull(void *cd, char **inbuf, size_t *inbytesleft, return 0; } -static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft, +static size_t ucs2hex_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 2 && *outbytesleft >= 1) { @@ -471,8 +478,32 @@ static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft, return 0; } +static size_t iconv_swab(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int n; + + n = MIN(*inbytesleft, *outbytesleft); + + swab(*inbuf, *outbuf, (n&~1)); + if (n&1) { + (*outbuf)[n-1] = 0; + } + + (*inbytesleft) -= n; + (*outbytesleft) -= n; + (*inbuf) += n; + (*outbuf) += n; + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} -static size_t iconv_copy(void *cd, char **inbuf, size_t *inbytesleft, +static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { int n; @@ -494,11 +525,11 @@ static size_t iconv_copy(void *cd, char **inbuf, size_t *inbytesleft, return 0; } -static size_t utf8_pull(void *cd, char **inbuf, size_t *inbytesleft, +static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 1 && *outbytesleft >= 2) { - unsigned char *c = (unsigned char *)*inbuf; + const unsigned char *c = (const unsigned char *)*inbuf; unsigned char *uc = (unsigned char *)*outbuf; int len = 1; @@ -541,12 +572,12 @@ badseq: return -1; } -static size_t utf8_push(void *cd, char **inbuf, size_t *inbytesleft, +static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { while (*inbytesleft >= 2 && *outbytesleft >= 1) { unsigned char *c = (unsigned char *)*outbuf; - unsigned char *uc = (unsigned char *)*inbuf; + const unsigned char *uc = (const unsigned char *)*inbuf; int len=1; if (uc[1] & 0xf8) { -- cgit From d9a1327474853c62e7059edcf9e7772eb574a501 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 1 Sep 2004 05:17:40 +0000 Subject: r2163: converted samba3 to use the new utf-16 aware iconv code. Also changed iconv to recognise UCS-2LE and UTF-16LE as synonyms, which means this change should be more robust when applied in trees that treat UCS-2LE or UTF-16LE as correct. (This used to be commit 92c9fcaec4299ddc16f9d6568a695b1fe161be33) --- source3/lib/iconv.c | 272 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 208 insertions(+), 64 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index e10e42328c..17cafdcbd6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -66,6 +66,7 @@ static struct charset_functions builtin_functions[] = { {"UCS-2LE", iconv_copy, iconv_copy}, {"UTF-16LE", iconv_copy, iconv_copy}, {"UCS-2BE", iconv_swab, iconv_swab}, + {"UTF-16BE", iconv_swab, iconv_swab}, /* we include the UTF-8 alias to cope with differing locale settings */ {"UTF8", utf8_pull, utf8_push}, @@ -189,6 +190,13 @@ size_t smb_iconv(smb_iconv_t cd, return 0; } + +static BOOL is_utf16(const char *name) +{ + return strcasecmp(name, "UCS-2LE") == 0 || + strcasecmp(name, "UTF-16LE") == 0; +} + /* simple iconv_open() wrapper */ @@ -227,13 +235,17 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) /* check if we can use iconv for this conversion */ #ifdef HAVE_NATIVE_ICONV if (!ret->pull) { - ret->cd_pull = iconv_open("UCS-2LE", fromcode); + ret->cd_pull = iconv_open("UTF-16LE", fromcode); + if (ret->cd_pull == (iconv_t)-1) + ret->cd_pull = iconv_open("UCS-2LE", fromcode); if (ret->cd_pull != (iconv_t)-1) ret->pull = sys_iconv; } if (!ret->push) { - ret->cd_push = iconv_open(tocode, "UCS-2LE"); + ret->cd_push = iconv_open(tocode, "UTF-16LE"); + if (ret->cd_push == (iconv_t)-1) + ret->cd_push = iconv_open(tocode, "UCS-2LE"); if (ret->cd_push != (iconv_t)-1) ret->push = sys_iconv; } @@ -263,13 +275,13 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } /* check for conversion to/from ucs2 */ - if (strcasecmp(fromcode, "UCS-2LE") == 0 && to) { + if (is_utf16(fromcode) && to) { ret->direct = to->push; ret->push = ret->pull = NULL; return ret; } - if (strcasecmp(tocode, "UCS-2LE") == 0 && from) { + if (is_utf16(tocode) && from) { ret->direct = from->pull; ret->push = ret->pull = NULL; return ret; @@ -277,13 +289,13 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) /* Check if we can do the conversion direct */ #ifdef HAVE_NATIVE_ICONV - if (strcasecmp(fromcode, "UCS-2LE") == 0) { + if (is_utf16(fromcode)) { ret->direct = sys_iconv; ret->cd_direct = ret->cd_push; ret->cd_push = NULL; return ret; } - if (strcasecmp(tocode, "UCS-2LE") == 0) { + if (is_utf16(tocode)) { ret->direct = sys_iconv; ret->cd_direct = ret->cd_pull; ret->cd_pull = NULL; @@ -528,99 +540,231 @@ static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft, static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { - while (*inbytesleft >= 1 && *outbytesleft >= 2) { - const unsigned char *c = (const unsigned char *)*inbuf; - unsigned char *uc = (unsigned char *)*outbuf; - int len = 1; + size_t in_left=*inbytesleft, out_left=*outbytesleft; + const uint8_t *c = (const uint8_t *)*inbuf; + uint8_t *uc = (uint8_t *)*outbuf; + while (in_left >= 1 && out_left >= 2) { if ((c[0] & 0x80) == 0) { uc[0] = c[0]; uc[1] = 0; - } else if ((c[0] & 0xf0) == 0xe0) { - if (*inbytesleft < 3) { - DEBUG(0,("short utf8 char\n")); - goto badseq; + c += 1; + in_left -= 1; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xe0) == 0xc0) { + if (in_left < 2 || + (c[1] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; + } + uc[1] = (c[0]>>2) & 0x7; + uc[0] = (c[0]<<6) | (c[1]&0x3f); + c += 2; + in_left -= 2; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xf0) == 0xe0) { + if (in_left < 3 || + (c[1] & 0xc0) != 0x80 || + (c[2] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; } uc[1] = ((c[0]&0xF)<<4) | ((c[1]>>2)&0xF); uc[0] = (c[1]<<6) | (c[2]&0x3f); - len = 3; - } else if ((c[0] & 0xe0) == 0xc0) { - if (*inbytesleft < 2) { - DEBUG(0,("short utf8 char\n")); - goto badseq; + c += 3; + in_left -= 3; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xf8) == 0xf0) { + unsigned int codepoint; + if (in_left < 4 || + (c[1] & 0xc0) != 0x80 || + (c[2] & 0xc0) != 0x80 || + (c[3] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; } - uc[1] = (c[0]>>2) & 0x7; - uc[0] = (c[0]<<6) | (c[1]&0x3f); - len = 2; + codepoint = + (c[3]&0x3f) | + ((c[2]&0x3f)<<6) | + ((c[1]&0x3f)<<12) | + ((c[0]&0x7)<<18); + if (codepoint < 0x10000) { + /* accept UTF-8 characters that are not + minimally packed, but pack the result */ + uc[0] = (codepoint & 0xFF); + uc[1] = (codepoint >> 8); + c += 4; + in_left -= 4; + out_left -= 2; + uc += 2; + continue; + } + + codepoint -= 0x10000; + + if (out_left < 4) { + errno = E2BIG; + goto error; + } + + uc[0] = (codepoint>>10) & 0xFF; + uc[1] = (codepoint>>18) | 0xd8; + uc[2] = codepoint & 0xFF; + uc[3] = ((codepoint>>8) & 0x3) | 0xdc; + c += 4; + in_left -= 4; + out_left -= 4; + uc += 4; + continue; } - (*inbuf) += len; - (*inbytesleft) -= len; - (*outbytesleft) -= 2; - (*outbuf) += 2; + /* we don't handle 5 byte sequences */ + errno = EINVAL; + goto error; } - if (*inbytesleft > 0) { + if (in_left > 0) { errno = E2BIG; - return -1; + goto error; } - + + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = c; + *outbuf = uc; return 0; -badseq: - errno = EINVAL; +error: + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = c; + *outbuf = uc; return -1; } static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) + char **outbuf, size_t *outbytesleft) { - while (*inbytesleft >= 2 && *outbytesleft >= 1) { - unsigned char *c = (unsigned char *)*outbuf; - const unsigned char *uc = (const unsigned char *)*inbuf; - int len=1; - - if (uc[1] & 0xf8) { - if (*outbytesleft < 3) { - DEBUG(0,("short utf8 write\n")); - goto toobig; + size_t in_left=*inbytesleft, out_left=*outbytesleft; + uint8_t *c = (uint8_t *)*outbuf; + const uint8_t *uc = (const uint8_t *)*inbuf; + + while (in_left >= 2 && out_left >= 1) { + unsigned int codepoint; + + if (uc[1] == 0 && !(uc[0] & 0x80)) { + /* simplest case */ + c[0] = uc[0]; + in_left -= 2; + out_left -= 1; + uc += 2; + c += 1; + continue; + } + + if ((uc[1]&0xf8) == 0) { + /* next simplest case */ + if (out_left < 2) { + errno = E2BIG; + goto error; } - c[0] = 0xe0 | (uc[1]>>4); - c[1] = 0x80 | ((uc[1]&0xF)<<2) | (uc[0]>>6); - c[2] = 0x80 | (uc[0]&0x3f); - len = 3; - } else if (uc[1] | (uc[0] & 0x80)) { - if (*outbytesleft < 2) { - DEBUG(0,("short utf8 write\n")); - goto toobig; + c[0] = 0xc0 | (uc[0]>>6) | (uc[1]<<2); + c[1] = 0x80 | (uc[0] & 0x3f); + in_left -= 2; + out_left -= 2; + uc += 2; + c += 2; + continue; + } + + if ((uc[1] & 0xfc) == 0xdc) { + /* its the second part of a 4 byte sequence. Illegal */ + if (in_left < 4) { + errno = EINVAL; + } else { + errno = EILSEQ; } - c[0] = 0xc0 | (uc[1]<<2) | (uc[0]>>6); - c[1] = 0x80 | (uc[0]&0x3f); - len = 2; - } else { - c[0] = uc[0]; + goto error; } + if ((uc[1] & 0xfc) != 0xd8) { + codepoint = uc[0] | (uc[1]<<8); + if (out_left < 3) { + errno = E2BIG; + goto error; + } + c[0] = 0xe0 | (codepoint >> 12); + c[1] = 0x80 | ((codepoint >> 6) & 0x3f); + c[2] = 0x80 | (codepoint & 0x3f); + + in_left -= 2; + out_left -= 3; + uc += 2; + c += 3; + continue; + } - (*inbytesleft) -= 2; - (*outbytesleft) -= len; - (*inbuf) += 2; - (*outbuf) += len; + /* its the first part of a 4 byte sequence */ + if (in_left < 4) { + errno = EINVAL; + goto error; + } + if ((uc[3] & 0xfc) != 0xdc) { + errno = EILSEQ; + goto error; + } + codepoint = 0x10000 + (uc[2] | ((uc[3] & 0x3)<<8) | + (uc[0]<<10) | ((uc[1] & 0x3)<<18)); + + if (out_left < 4) { + errno = E2BIG; + goto error; + } + c[0] = 0xf0 | (codepoint >> 18); + c[1] = 0x80 | ((codepoint >> 12) & 0x3f); + c[2] = 0x80 | ((codepoint >> 6) & 0x3f); + c[3] = 0x80 | (codepoint & 0x3f); + + in_left -= 4; + out_left -= 4; + uc += 4; + c += 4; } - if (*inbytesleft == 1) { + if (in_left == 1) { errno = EINVAL; - return -1; + goto error; } - if (*inbytesleft > 1) { + if (in_left > 1) { errno = E2BIG; - return -1; + goto error; } + + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = uc; + *outbuf = c; return 0; -toobig: - errno = E2BIG; +error: + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = uc; + *outbuf = c; return -1; } + -- cgit From b887c41253ec67288333fd20f282c89b139789a3 Mon Sep 17 00:00:00 2001 From: Paul Green Date: Mon, 6 Sep 2004 00:24:28 +0000 Subject: r2231: Fix iconv.c to use the Samba-supplied uint8 type not the uint8_t type, which does not exist on all platforms. (This used to be commit acc793ead7e61f1eb87864b676d26f5791367228) --- source3/lib/iconv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 17cafdcbd6..66a6e6cd8b 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -541,8 +541,8 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { size_t in_left=*inbytesleft, out_left=*outbytesleft; - const uint8_t *c = (const uint8_t *)*inbuf; - uint8_t *uc = (uint8_t *)*outbuf; + const uint8 *c = (const uint8 *)*inbuf; + uint8 *uc = (uint8 *)*outbuf; while (in_left >= 1 && out_left >= 2) { if ((c[0] & 0x80) == 0) { @@ -658,8 +658,8 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { size_t in_left=*inbytesleft, out_left=*outbytesleft; - uint8_t *c = (uint8_t *)*outbuf; - const uint8_t *uc = (const uint8_t *)*inbuf; + uint8 *c = (uint8 *)*outbuf; + const uint8 *uc = (const uint8 *)*inbuf; while (in_left >= 2 && out_left >= 1) { unsigned int codepoint; -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/iconv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 66a6e6cd8b..d58165fed0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -209,15 +209,15 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) from = charsets; to = charsets; - ret = (smb_iconv_t)malloc(sizeof(*ret)); + ret = SMB_MALLOC_P(struct _smb_iconv_t); if (!ret) { errno = ENOMEM; return (smb_iconv_t)-1; } - memset(ret, 0, sizeof(*ret)); + memset(ret, 0, sizeof(struct _smb_iconv_t)); - ret->from_name = strdup(fromcode); - ret->to_name = strdup(tocode); + ret->from_name = SMB_STRDUP(fromcode); + ret->to_name = SMB_STRDUP(tocode); /* check for the simplest null conversion */ if (strcasecmp(fromcode, tocode) == 0) { -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index d58165fed0..f23e4351c0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -135,7 +135,7 @@ static size_t sys_iconv(void *cd, { #ifdef HAVE_NATIVE_ICONV size_t ret = iconv((iconv_t)cd, - (char **)inbuf, inbytesleft, + CONST_DISCARD(char **, inbuf), inbytesleft, outbuf, outbytesleft); if (ret == (size_t)-1) { int saved_errno = errno; -- cgit From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index f23e4351c0..d58165fed0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -135,7 +135,7 @@ static size_t sys_iconv(void *cd, { #ifdef HAVE_NATIVE_ICONV size_t ret = iconv((iconv_t)cd, - CONST_DISCARD(char **, inbuf), inbytesleft, + (char **)inbuf, inbytesleft, outbuf, outbytesleft); if (ret == (size_t)-1) { int saved_errno = errno; -- cgit From 8d7c88667190fe286971ac4fffb64ee5bd9eeeb0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 03:24:00 +0000 Subject: r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4 x86_64 box. Jeremy. (This used to be commit d720867a788c735e56d53d63265255830ec21208) --- source3/lib/iconv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index d58165fed0..f738f45efa 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -642,15 +642,15 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (char *)c; + *outbuf = (char *)uc; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (char *)c; + *outbuf = (char *)uc; return -1; } @@ -755,16 +755,16 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (char *)uc; + *outbuf = (char *)c; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (char *)uc; + *outbuf = (char *)c; return -1; } -- cgit From 31693197bee0d71e83418c0fb72685fd848e358f Mon Sep 17 00:00:00 2001 From: Paul Green Date: Wed, 26 Apr 2006 15:41:25 +0000 Subject: r15283: Oh yeah. The build farm doesn't do much with head. OK, here is the patch to SAMBA_3_0 to declare prototypes for the initialization functions. These are the same changes I just made to head. --paulg (This used to be commit 17774387ad879b6a72dd1cf406326318add31b04) --- source3/lib/iconv.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index f738f45efa..c96243633f 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -51,6 +51,8 @@ * @sa Samba Developers Guide **/ +static_decl_charset; + static size_t ascii_pull(void *,const char **, size_t *, char **, size_t *); static size_t ascii_push(void *,const char **, size_t *, char **, size_t *); static size_t latin1_push(void *,const char **, size_t *, char **, size_t *); -- cgit From 8b4669c3c512484d456f8e0a16e2fd8e7499b026 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 12 Dec 2006 20:30:31 +0000 Subject: r20133: get rid of defined but not used warning - static function only used inside the #ifdef HAVE_NATIVE_ICONV (This used to be commit 43ab1d2ba5eb24fc22f8d53c650bf39e95fb133b) --- source3/lib/iconv.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index c96243633f..6e040b77f1 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -128,6 +128,7 @@ static void lazy_initialize_iconv(void) } } +#ifdef HAVE_NATIVE_ICONV /* if there was an error then reset the internal state, this ensures that we don't have a shift state remaining for character sets like SJIS */ @@ -135,7 +136,6 @@ static size_t sys_iconv(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { -#ifdef HAVE_NATIVE_ICONV size_t ret = iconv((iconv_t)cd, (char **)inbuf, inbytesleft, outbuf, outbytesleft); @@ -145,11 +145,8 @@ static size_t sys_iconv(void *cd, errno = saved_errno; } return ret; -#else - errno = EINVAL; - return -1; -#endif } +#endif /** * This is a simple portable iconv() implementaion. -- cgit From 3611cb13edcf83ac7dd2be60646f8ec09970269a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Jun 2007 17:25:13 +0000 Subject: r23572: Ensure we obey Unicode consortium restrictions. Code based on patch from MORIYAMA Masayuki . Jeremy. (This used to be commit 0f10d2ed312115998d5ce1dc88a8d9207c9e4959) --- source3/lib/iconv.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6e040b77f1..90e2faab6f 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -544,6 +544,8 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, uint8 *uc = (uint8 *)*outbuf; while (in_left >= 1 && out_left >= 2) { + unsigned int codepoint; + if ((c[0] & 0x80) == 0) { uc[0] = c[0]; uc[1] = 0; @@ -560,8 +562,14 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, errno = EILSEQ; goto error; } - uc[1] = (c[0]>>2) & 0x7; - uc[0] = (c[0]<<6) | (c[1]&0x3f); + codepoint = (c[1]&0x3f) | ((c[0]&0x1f)<<6); + if (codepoint < 0x80) { + /* don't accept UTF-8 characters that are not minimally packed */ + errno = EILSEQ; + goto error; + } + uc[1] = codepoint >> 8; + uc[0] = codepoint & 0xff; c += 2; in_left -= 2; out_left -= 2; @@ -576,8 +584,14 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, errno = EILSEQ; goto error; } - uc[1] = ((c[0]&0xF)<<4) | ((c[1]>>2)&0xF); - uc[0] = (c[1]<<6) | (c[2]&0x3f); + codepoint = (c[2]&0x3f) | ((c[1]&0x3f)<<6) | ((c[0]&0xf)<<12); + if (codepoint < 0x800) { + /* don't accept UTF-8 characters that are not minimally packed */ + errno = EILSEQ; + goto error; + } + uc[1] = codepoint >> 8; + uc[0] = codepoint & 0xff; c += 3; in_left -= 3; out_left -= 2; @@ -586,7 +600,6 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, } if ((c[0] & 0xf8) == 0xf0) { - unsigned int codepoint; if (in_left < 4 || (c[1] & 0xc0) != 0x80 || (c[2] & 0xc0) != 0x80 || @@ -599,16 +612,10 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, ((c[2]&0x3f)<<6) | ((c[1]&0x3f)<<12) | ((c[0]&0x7)<<18); - if (codepoint < 0x10000) { - /* accept UTF-8 characters that are not - minimally packed, but pack the result */ - uc[0] = (codepoint & 0xFF); - uc[1] = (codepoint >> 8); - c += 4; - in_left -= 4; - out_left -= 2; - uc += 2; - continue; + if (codepoint < 0x10000 || codepoint > 0x10ffff) { + /* don't accept UTF-8 characters that are not minimally packed */ + errno = EILSEQ; + goto error; } codepoint -= 0x10000; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 90e2faab6f..36fdd8b820 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/iconv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 36fdd8b820..6b42384ae2 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6b42384ae2..6575dba5a9 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -116,7 +116,7 @@ NTSTATUS smb_register_charset(struct charset_functions *funcs) static void lazy_initialize_iconv(void) { - static BOOL initialized; + static bool initialized; int i; if (!initialized) { @@ -189,7 +189,7 @@ size_t smb_iconv(smb_iconv_t cd, } -static BOOL is_utf16(const char *name) +static bool is_utf16(const char *name) { return strcasecmp(name, "UCS-2LE") == 0 || strcasecmp(name, "UTF-16LE") == 0; -- cgit From 06d0790c0799112b89534a646e78d0cb38b06e20 Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Thu, 3 Jul 2008 22:53:42 -0700 Subject: Fix various build warnings This fixes various build warnings on our platform. I'm sure I haven't caught them all, but it's a start. (This used to be commit 6b73f259cb67d9dda9127907d706f9244a871fa3) --- source3/lib/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/iconv.c') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6575dba5a9..3ceb637b8e 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -136,7 +136,7 @@ static size_t sys_iconv(void *cd, char **outbuf, size_t *outbytesleft) { size_t ret = iconv((iconv_t)cd, - (char **)inbuf, inbytesleft, + (void *)inbuf, inbytesleft, outbuf, outbytesleft); if (ret == (size_t)-1) { int saved_errno = errno; -- cgit