From 0e8fd3398771da2f016d72830179507f3edda51b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 4 May 1996 07:50:46 +0000 Subject: Initial version imported to CVS (This used to be commit 291551d80711daab7b7581720bcd9a08d6096517) --- source3/lib/charcnv.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 source3/lib/charcnv.c (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c new file mode 100644 index 0000000000..049390f2a4 --- /dev/null +++ b/source3/lib/charcnv.c @@ -0,0 +1,126 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Character set conversion Extensions + Copyright (C) Andrew Tridgell 1992-1994 + + 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" +extern int DEBUGLEVEL; + +static char cvtbuf[1024]; + +static mapsinited = 0; + +static char unix2dos[256]; +static char dos2unix[256]; + +static void initmaps() { + int k; + + for (k = 0; k < 256; k++) unix2dos[k] = k; + for (k = 0; k < 256; k++) dos2unix[k] = k; + + mapsinited = 1; +} + +static void update_map(char * str) { + char *p; + + for (p = str; *p; p++) { + if (p[1]) { + unix2dos[(unsigned char)*p] = p[1]; + dos2unix[(unsigned char)p[1]] = *p; + p++; + } + } +} + +static void initiso() { + + if (!mapsinited) initmaps(); + + update_map("\241\255\242\233\243\234\244\236\245\235\246\272\247\025\250\251"); + update_map("\251\273\252\246\253\256\254\252\255\274\256\310\257\257\260\370"); + update_map("\261\361\262\375\263\264\264\265\265\266\266\024\267\371\270\267"); + update_map("\271\270\272\247\273\275\274\254\275\253\276\276\277\250\200\277"); + update_map("\301\300\302\301\303\302\304\216\305\217\306\222\307\200\310\303"); + update_map("\311\220\312\305\313\306\314\307\315\315\316\317\317\320\320\311"); + update_map("\321\245\322\321\323\322\324\323\325\324\326\231\327\312\330\325"); + update_map("\331\326\332\327\333\330\334\232\335\313\336\314\337\341\340\205"); + update_map("\341\240\342\203\343\331\344\204\345\206\346\221\347\207\350\212"); + update_map("\351\202\352\210\353\211\354\215\355\241\356\214\357\213\360\316"); + update_map("\361\244\362\225\363\242\364\223\365\332\366\224\367\366\370\362"); + update_map("\371\227\372\243\373\226\374\201\375\304\376\263\377\230"); +} + +/* + * Convert unix to dos + */ +char * +unix2dos_format(char *str,BOOL overwrite) +{ + char *p; + char *dp; + + if (!mapsinited) initmaps(); + if (overwrite) { + for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } +} + +/* + * Convert dos to unix + */ +char * +dos2unix_format (char *str, BOOL overwrite) +{ + char *p; + char *dp; + + if (!mapsinited) initmaps(); + if (overwrite) { + for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } +} + + +/* + * Interpret character set. + */ +int +interpret_character_set (char *str, int def) +{ + + if (strequal (str, "iso8859-1")) { + initiso(); + return def; + } else { + DEBUG(0,("unrecognized character set\n")); + } + return def; +} -- cgit From a2c1623827406667a4f2f058c24f1d971f6627f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:42:03 +0000 Subject: a huge pile of changes :-) The biggest thing is the integration of Lukes new nmbd. Its still largely untested, so we will really need some feedback I've also added auto prototype generation and cleaned up a lot of minor things as a result (This used to be commit 0d8dcfa13c527ec2c8aca39ba49c09e4e694b26c) --- source3/lib/charcnv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 049390f2a4..d9ee551d6a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -71,8 +71,7 @@ static void initiso() { /* * Convert unix to dos */ -char * -unix2dos_format(char *str,BOOL overwrite) +char *unix2dos_format(char *str,BOOL overwrite) { char *p; char *dp; @@ -91,8 +90,7 @@ unix2dos_format(char *str,BOOL overwrite) /* * Convert dos to unix */ -char * -dos2unix_format (char *str, BOOL overwrite) +char *dos2unix_format(char *str, BOOL overwrite) { char *p; char *dp; @@ -112,8 +110,7 @@ dos2unix_format (char *str, BOOL overwrite) /* * Interpret character set. */ -int -interpret_character_set (char *str, int def) +int interpret_character_set(char *str, int def) { if (strequal (str, "iso8859-1")) { -- cgit From 8bc7d6bebd4fcf8c95cb6d58da14404a5e46de91 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 9 Jan 1997 18:02:17 +0000 Subject: Makefile: Changes to split Solaris into Solaris2.3 and previous, and 2.4 and after from Paul Eggert. Makefile: Added AMIGA changes from Rask Ingemann Lambertsen . charset.c: Patch for Western European Languages from Josef Hinteregger charset.h: Patch for Western European Languages from Josef Hinteregger clitar.c: Patch to re-sync after read fail from (lost contributor name, sorry). includes.h: Patch for AMIGA from Rask Ingemann Lambertsen includes.h: Patch for SunOS atexit by Jeremy (jra@cygnus.com) interface.c: Patch for AMIGA from Rask Ingemann Lambertsen kanji.h: Patch for Western European Languages from Josef Hinteregger locking.c: Patch to fix file locking from Jeremy (jra@cygnus.com) locking.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) pipes.c: Patch to fix file locking from Jeremy (jra@cygnus.com) proto.h: Patch to fix file locking from Jeremy (jra@cygnus.com) reply.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch for FAST_SHARE_MODE fix from (lost contributor name, sorry). smb.h: Patch to fix file locking from Jeremy (jra@cygnus.com) smb.h: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) status.c: Patch to fix file locking from Jeremy (jra@cygnus.com) statuc.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) system.c: Patch for Western European Languages from Josef Hinteregger trans2.c: Patch to fix file locking from Jeremy (jra@cygnus.com) trans2.c: Patch to fix volume name reported to Win95 from Jeremy (jra@cygnus.com) util.c: Patch for Western European Languages from Josef Hinteregger util.c: Patch to fix client_name from continuously returning UNKNOWN (from various contributors). version.h: Update to 1.9.16p10. (This used to be commit 03d28fa32eb094affa33133ebe2602fdb70f6361) --- source3/lib/charcnv.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d9ee551d6a..4654101a5c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#define CTRLZ 26 extern int DEBUGLEVEL; static char cvtbuf[1024]; @@ -52,20 +53,30 @@ static void update_map(char * str) { static void initiso() { + int i; if (!mapsinited) initmaps(); - update_map("\241\255\242\233\243\234\244\236\245\235\246\272\247\025\250\251"); - update_map("\251\273\252\246\253\256\254\252\255\274\256\310\257\257\260\370"); - update_map("\261\361\262\375\263\264\264\265\265\266\266\024\267\371\270\267"); - update_map("\271\270\272\247\273\275\274\254\275\253\276\276\277\250\200\277"); - update_map("\301\300\302\301\303\302\304\216\305\217\306\222\307\200\310\303"); - update_map("\311\220\312\305\313\306\314\307\315\315\316\317\317\320\320\311"); - update_map("\321\245\322\321\323\322\324\323\325\324\326\231\327\312\330\325"); - update_map("\331\326\332\327\333\330\334\232\335\313\336\314\337\341\340\205"); - update_map("\341\240\342\203\343\331\344\204\345\206\346\221\347\207\350\212"); - update_map("\351\202\352\210\353\211\354\215\355\241\356\214\357\213\360\316"); - update_map("\361\244\362\225\363\242\364\223\365\332\366\224\367\366\370\362"); - update_map("\371\227\372\243\373\226\374\201\375\304\376\263\377\230"); + /* Do not map undefined characters to some accidental code */ + for (i = 128; i < 256; i++) + { + unix2dos[i] = CTRLZ; + dos2unix[i] = CTRLZ; + } + +/* MSDOS Code Page 850 -> ISO-8859 */ +update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); +update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); +update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); +update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); +update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); +update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); +update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); +update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); +update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); +update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); +update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); +update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); + } /* -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4654101a5c..cf4ae4edb6 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Character set conversion Extensions - Copyright (C) Andrew Tridgell 1992-1994 + Copyright (C) Andrew Tridgell 1992-1997 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 -- cgit From 441855fe0e6b37201d2ef6a8375de4bcc76b9752 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 21:17:59 +0000 Subject: status.c: Added brief option. Patch from ccctim@mailbox.ucdavis.edu client.c: Added translation of '/' characters to '\' characters. Suggested by friedl@mtndew.com (Stephen J. Friedl) charcn.c: Fix for iso8859-2 (Eastern European) conversions based on a patch from Miroslaw M. Maczka (This used to be commit 27708a73cef690ea8aea0f3d82619eaed1fe476d) --- source3/lib/charcnv.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cf4ae4edb6..b6debbec4a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -51,7 +51,7 @@ static void update_map(char * str) { } } -static void initiso() { +static void init_iso8859_1() { int i; if (!mapsinited) initmaps(); @@ -79,6 +79,25 @@ update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); } +/* Init for eastern european languages. May need more work ? */ + +static void init_iso8859_2() { + + int i; + if (!mapsinited) initmaps(); + + /* Do not map undefined characters to some accidental code */ + for (i = 128; i < 256; i++) + { + unix2dos[i] = CTRLZ; + dos2unix[i] = CTRLZ; + } + +update_map("\241\244\306\217\312\250\243\235\321\343\323\340\246\227\254\215"); +update_map("\257\275\261\245\346\206\352\251\263\210\361\344\363\242\266\230"); +update_map("\274\253\277\276"); +} + /* * Convert unix to dos */ @@ -125,8 +144,9 @@ int interpret_character_set(char *str, int def) { if (strequal (str, "iso8859-1")) { - initiso(); - return def; + init_iso8859_1(); + } else if (strequal (str, "iso8859-2")) { + init_iso8859_2(); } else { DEBUG(0,("unrecognized character set\n")); } -- cgit From 3ab97ebe6db1a5a4a0573c7c8482c94876bbce9a Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 30 May 1997 20:40:48 +0000 Subject: charcnv.c: Fixed silly bugs detected on IRIX. client.c: Fixed silly bugs detected on IRIX. namedbname.c: Stopped 1d names from being registered in WINS db. namedbsubnet.c: Only register 1e names on broadcast subnet. nameelect.c: Changed add_my_name entries. Forced host announces if we have less than 10 servers listed. Fixed registering 1b domain name issues. namepacket.c: Added error message when dgram discarded. nameserv.c: Added notion of 'direct' names that are not registered on the network. Needed to get around bugs in earlier nmbd handling of DOMAIN(1b) names. nameservreply.c:Tidied up debug message. nameservresp.c: Added response_name_query_domain() code. Deals with re-registering DOMAIN(1b) name. nmbd.c: Fixed silly bugs detected on IRIX. nmblib.c: Added paranoia debugs. proto.h: Updated remove_name_entry(), add_my_name_entry(). server.c: Fixed silly bugs detected on IRIX. trans2.c: Fixed silly bugs detected on IRIX. uid.c: Fixed silly bugs detected on IRIX. version.h: Updated to alpha3. Jeremy (jallison@whistle.com). (This used to be commit f08222bd8b86a061c52d22015f946a4737eb47fd) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b6debbec4a..6be455c47b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -25,7 +25,7 @@ extern int DEBUGLEVEL; static char cvtbuf[1024]; -static mapsinited = 0; +static BOOL mapsinited = 0; static char unix2dos[256]; static char dos2unix[256]; @@ -36,7 +36,7 @@ static void initmaps() { for (k = 0; k < 256; k++) unix2dos[k] = k; for (k = 0; k < 256; k++) dos2unix[k] = k; - mapsinited = 1; + mapsinited = True; } static void update_map(char * str) { -- cgit From 30416c0b8a0f54f6cc1179c2e00860eaf5f58401 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Sep 1997 20:17:32 +0000 Subject: charcnv.c client.c clitar.c kanji.c kanji.h loadparm.c mangle.c smb.h util.c: Big merge to allow KANJI support to be in the main binary without explicitly compiling with it. locking.c: Fix for smbstatus not being able to read files. namepacket.c: Removed unneccesary debug statement. trans2.c: Added Luke's proposed fix (ifdefed out until further testing). nmblookup.c: Fixed bug where query fails and status is done on bogus IP. Jeremy (jallison@whistle.com) (This used to be commit 9196255022ae8c51b527412747b324819bea2c13) --- source3/lib/charcnv.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6be455c47b..a7dff4224b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -107,13 +107,18 @@ char *unix2dos_format(char *str,BOOL overwrite) char *dp; if (!mapsinited) initmaps(); - if (overwrite) { - for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p]; - *dp = 0; - return cvtbuf; + + if(lp_client_code_page() == KANJI_CODEPAGE) + return (*_unix_to_dos)(str, overwrite); + else { + if (overwrite) { + for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } } @@ -126,13 +131,18 @@ char *dos2unix_format(char *str, BOOL overwrite) char *dp; if (!mapsinited) initmaps(); - if (overwrite) { - for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p]; - *dp = 0; - return cvtbuf; + + if(lp_client_code_page() == KANJI_CODEPAGE) + return (*_dos_to_unix)(str, overwrite); + else { + if (overwrite) { + for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } } -- cgit From 51f20adc6b964bad6e5bfbf69da68e1e6f45b13e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Nov 1997 07:09:12 +0000 Subject: added true enumerated types in loadparm.c. Now we don't need all those "interpret_security" and similar functions. This also means that testparm produces string values for these enumerated types rather than an integer. This was done to make the web interface much cleaner. While I was doing this I found a couple of very nasty bugs in the parm_table code. Someone had added a handle_character_set() function that treated the char** pointer for a P_STRING as an integer! This would have caused memory corruption for anyone using the "character set" option. The loadparm code is delicate - please be careful about using it's more esoteric features! I've also removed the "coding system" global and made it a P_STRING. The integer value was never used anywhere in Samba. (This used to be commit bac6b0daa288e879330e3d585582122bb93a1ffb) --- source3/lib/charcnv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a7dff4224b..e1a7ac01db 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -150,9 +150,8 @@ char *dos2unix_format(char *str, BOOL overwrite) /* * Interpret character set. */ -int interpret_character_set(char *str, int def) +void interpret_character_set(char *str) { - if (strequal (str, "iso8859-1")) { init_iso8859_1(); } else if (strequal (str, "iso8859-2")) { @@ -160,5 +159,4 @@ int interpret_character_set(char *str, int def) } else { DEBUG(0,("unrecognized character set\n")); } - return def; } -- cgit From 1ea8ceac458501719a055700902d456304c4ee0a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 17 Jan 1998 07:08:21 +0000 Subject: charcnv.c: Added codepage 866 support onto the file system. Patch from Max Khon . chgpasswd.c: Allow old RAP change password to work with encrypted passwords. Samba can now allow Windows 95/NT clients to securely change the Lanman password ! (But not the NT hash - that gets lost). ipc.c: smbdes.c: smbpass.c: Support for the above. server.c: #ifdef'ed out fix for NT redirector bug. util.c: Fix NIS bug with server name. Jeremy. (This used to be commit cd9fad92d0316e5a0007ba3c5668906dc2f011f1) --- source3/lib/charcnv.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index e1a7ac01db..f5d28baee4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -98,6 +98,62 @@ update_map("\257\275\261\245\346\206\352\251\263\210\361\344\363\242\266\230"); update_map("\274\253\277\276"); } +/* Init for russian language (iso8859-5) */ + +/* Added by Max Khon */ + +static void init_iso8859_5() +{ + int i; + if (!mapsinited) initmaps(); + + /* Do not map undefined characters to some accidental code */ + for (i = 128; i < 256; i++) + { + unix2dos[i] = CTRLZ; + dos2unix[i] = CTRLZ; + } + +/* MSDOS Code Page 866 -> ISO8859-5 */ +update_map("\200\260\201\261\202\262\203\263\204\264\205\265\206\266\207\267"); +update_map("\210\270\211\271\212\272\213\273\214\274\215\275\216\276\217\277"); +update_map("\220\300\221\301\222\302\223\303\224\304\225\305\226\306\227\307"); +update_map("\230\310\231\311\232\312\233\313\234\314\235\315\236\316\237\317"); +update_map("\240\320\241\321\242\322\243\323\244\324\245\325\246\326\247\327"); +update_map("\250\330\251\331\252\332\253\333\254\334\255\335\256\336\257\337"); +update_map("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347"); +update_map("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357"); +update_map("\360\241\361\361\362\244\363\364\364\247\365\367\366\256\367\376"); +update_map("\374\360\377\240"); +} + +/* Init for russian language (koi8) */ + +static void init_koi8_r() +{ + if (!mapsinited) initmaps(); + + /* There aren't undefined characters between 128 and 255 */ + +/* MSDOS Code Page 866 -> KOI8-R */ +update_map("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264"); +update_map("\210\302\211\301\212\305\213\337\214\334\215\333\216\335\217\336"); +update_map("\220\260\221\261\222\262\223\364\224\376\225\371\226\373\227\367"); +update_map("\230\363\231\362\232\377\233\365\234\370\235\375\236\372\237\366"); +update_map("\240\315\241\272\242\325\243\361\244\326\245\311\246\270\247\267"); +update_map("\250\273\251\324\252\323\253\310\254\276\255\275\256\274\257\306"); +update_map("\260\307\261\314\262\265\263\360\264\266\265\271\266\321\267\322"); +update_map("\270\313\271\317\272\320\273\312\274\330\275\327\276\316\277\374"); +update_map("\300\356\301\240\302\241\303\346\304\244\305\245\306\344\307\243"); +update_map("\310\345\311\250\312\251\313\252\314\253\315\254\316\255\317\256"); +update_map("\320\257\321\357\322\340\323\341\324\342\325\343\326\246\327\242"); +update_map("\330\354\331\353\332\247\333\350\334\355\335\351\336\347\337\352"); +update_map("\340\236\341\200\342\201\343\226\344\204\345\205\346\224\347\203"); +update_map("\350\225\351\210\352\211\353\212\354\213\355\214\356\215\357\216"); +update_map("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202"); +update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232"); +} + /* * Convert unix to dos */ @@ -156,6 +212,10 @@ void interpret_character_set(char *str) init_iso8859_1(); } else if (strequal (str, "iso8859-2")) { init_iso8859_2(); + } else if (strequal (str, "iso8859-5")) { + init_iso8859_5(); + } else if (strequal (str, "koi8-r")) { + init_koi8_r(); } else { DEBUG(0,("unrecognized character set\n")); } -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index f5d28baee4..f02fcb2f92 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Character set conversion Extensions - Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Andrew Tridgell 1992-1998 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 -- cgit From b7fb6c6b38784d25c9c85e9b27b08e30111dbd0c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Mar 1998 20:19:14 +0000 Subject: Change the multibyte character set support so that Kanji support is one case of multibyte character support, rather than being a specific case in single byte character support. This allows us to add Big5 Chinese support (code page 950) and Korean Hangul support (code page 949) at very little cost. Also allows us to easily add future multibyte code pages. Makefile: Added codepages 949, 950 as we now support more multibyte codepages. asyncdns.c: Fixed problem with child being re-spawned when parent killed. charcnv.c charset.c client.c clitar.c kanji.c kanji.h smb.h util.c loadparm.c: Generic multibyte codepage support (adding Big5 Chinese and Korean Hangul). nmbd.c: Fixed problem with child being re-spawned when parent killed. mangle.c: Modified str_checksum so that first 15 characters have more effect on outcome. This helps with short name mangling as most 'long' names are still shorter than 15 chars (bug was foobar_mng and foobar_sum would hash to the same value, with the modified code they hash differently. Jeremy. (This used to be commit 299016338cfb47f0c585875ef9b468121fcee97d) --- source3/lib/charcnv.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index f02fcb2f92..20db58e4ab 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -164,9 +164,6 @@ char *unix2dos_format(char *str,BOOL overwrite) if (!mapsinited) initmaps(); - if(lp_client_code_page() == KANJI_CODEPAGE) - return (*_unix_to_dos)(str, overwrite); - else { if (overwrite) { for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; return str; @@ -175,7 +172,6 @@ char *unix2dos_format(char *str,BOOL overwrite) *dp = 0; return cvtbuf; } - } } /* @@ -188,9 +184,6 @@ char *dos2unix_format(char *str, BOOL overwrite) if (!mapsinited) initmaps(); - if(lp_client_code_page() == KANJI_CODEPAGE) - return (*_dos_to_unix)(str, overwrite); - else { if (overwrite) { for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; return str; @@ -199,7 +192,6 @@ char *dos2unix_format(char *str, BOOL overwrite) *dp = 0; return cvtbuf; } - } } -- cgit From d99d6f0d2e956037f5a60250b044ccdde9d6a330 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Apr 1998 00:45:43 +0000 Subject: Updated Eastern European translation table from dan@feld.cvut.cz. Jeremy. (This used to be commit 84d858782eca2077cd0ce089b156938fa122cf93) --- source3/lib/charcnv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 20db58e4ab..e92e8170f0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -79,7 +79,7 @@ update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); } -/* Init for eastern european languages. May need more work ? */ +/* Init for eastern european languages. */ static void init_iso8859_2() { @@ -93,9 +93,25 @@ static void init_iso8859_2() { dos2unix[i] = CTRLZ; } -update_map("\241\244\306\217\312\250\243\235\321\343\323\340\246\227\254\215"); -update_map("\257\275\261\245\346\206\352\251\263\210\361\344\363\242\266\230"); -update_map("\274\253\277\276"); +/* + * Tranlation table created by dan@feld.cvut.cz + * Requires client code page = 852 + * and character set = ISO8859-2 in smb.conf + */ +update_map("\173\173\174\174\175\175\176\176\241\244\242\364\243\235\244\317"); +update_map("\245\225\246\227\247\365\250\371\251\346\252\270\253\233\254\215"); +update_map("\256\246\257\275\261\245\262\362\263\210\264\357\265\226\2263\210\264\357\265\226\266\230"); +update_map("\267\363\270\367\271\347\272\255\273\234\274\253\275\361\276\247"); +update_map("\277\276\300\350\301\265\302\266\303\306\304\216\305\221\306\217"); +update_map("\307\200\310\254\311\220\312\250\313\323\314\267\315\326\316\327"); +update_map("\317\322\320\321\321\343\322\325\323\340\324\342\325\212\326\231"); +update_map("\327\236\330\374\331\336\332\351\333\353\334\232\335\355\336\335"); +update_map("\337\341\340\352\341\240\342\203\343\307\344\204\345\222\346\206"); +update_map("\347\207\350\237\351\202\352\251\353\211\354\330\355\241\356\214"); +update_map("\357\324\360\320\361\344\362\345\363\242\364\223\365\213\366\224"); +update_map("\367\366\370\375\371\205\372\243\373\373\374\201\375\354\376\356"); +update_map("\377\372"); + } /* Init for russian language (iso8859-5) */ -- cgit From cac6a060af598bf94e6414b06e7365ec51ca360e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Apr 1998 19:24:06 +0000 Subject: Changes to allow Samba to be compiled with -Wstrict-prototypes with gcc. (Not a big change although it looks like it :-). Jeremy. (This used to be commit cd2613c57261456485fe4eeecfda209ada70de8e) --- source3/lib/charcnv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index e92e8170f0..42be32ccb3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -30,7 +30,7 @@ static BOOL mapsinited = 0; static char unix2dos[256]; static char dos2unix[256]; -static void initmaps() { +static void initmaps(void) { int k; for (k = 0; k < 256; k++) unix2dos[k] = k; @@ -51,7 +51,7 @@ static void update_map(char * str) { } } -static void init_iso8859_1() { +static void init_iso8859_1(void) { int i; if (!mapsinited) initmaps(); @@ -81,7 +81,7 @@ update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); /* Init for eastern european languages. */ -static void init_iso8859_2() { +static void init_iso8859_2(void) { int i; if (!mapsinited) initmaps(); @@ -118,7 +118,7 @@ update_map("\377\372"); /* Added by Max Khon */ -static void init_iso8859_5() +static void init_iso8859_5(void) { int i; if (!mapsinited) initmaps(); @@ -145,7 +145,7 @@ update_map("\374\360\377\240"); /* Init for russian language (koi8) */ -static void init_koi8_r() +static void init_koi8_r(void) { if (!mapsinited) initmaps(); -- cgit From 7b9a53b68079231fc0c65ee4a265de297031a161 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Apr 1998 19:23:10 +0000 Subject: reply.c: Fix bugs where debug statements were accessing the fd_ptr struct internals after Andrews' code had memset it to zero (this was causing core dumps). charcnv.c: Fixes for ISO8859-2 from Petr Hubeny . Jeremy. (This used to be commit df8783ca76d543d200c743f515a185cfea2880df) --- source3/lib/charcnv.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 42be32ccb3..b016a07fd7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -94,24 +94,24 @@ static void init_iso8859_2(void) { } /* - * Tranlation table created by dan@feld.cvut.cz + * Tranlation table created by Petr Hubeny * Requires client code page = 852 * and character set = ISO8859-2 in smb.conf */ -update_map("\173\173\174\174\175\175\176\176\241\244\242\364\243\235\244\317"); -update_map("\245\225\246\227\247\365\250\371\251\346\252\270\253\233\254\215"); -update_map("\256\246\257\275\261\245\262\362\263\210\264\357\265\226\2263\210\264\357\265\226\266\230"); -update_map("\267\363\270\367\271\347\272\255\273\234\274\253\275\361\276\247"); -update_map("\277\276\300\350\301\265\302\266\303\306\304\216\305\221\306\217"); -update_map("\307\200\310\254\311\220\312\250\313\323\314\267\315\326\316\327"); -update_map("\317\322\320\321\321\343\322\325\323\340\324\342\325\212\326\231"); -update_map("\327\236\330\374\331\336\332\351\333\353\334\232\335\355\336\335"); -update_map("\337\341\340\352\341\240\342\203\343\307\344\204\345\222\346\206"); -update_map("\347\207\350\237\351\202\352\251\353\211\354\330\355\241\356\214"); -update_map("\357\324\360\320\361\344\362\345\363\242\364\223\365\213\366\224"); -update_map("\367\366\370\375\371\205\372\243\373\373\374\201\375\354\376\356"); -update_map("\377\372"); +/* MSDOS Code Page 852 -> ISO-8859-2 */ +update_map("\241\244\242\364\243\235\244\317\245\225\246\227\247\365"); +update_map("\250\371\251\346\252\270\253\233\254\215\256\246\257\275"); +update_map("\261\245\262\362\263\210\264\357\265\226\266\230\267\363"); +update_map("\270\367\271\347\272\255\273\234\274\253\275\361\276\247\277\276"); +update_map("\300\350\301\265\302\266\303\306\304\216\305\221\306\217\307\200"); +update_map("\310\254\311\220\312\250\313\323\314\267\315\326\316\327\317\322"); +update_map("\320\321\321\343\322\325\323\340\324\342\325\212\326\231\327\236"); +update_map("\330\374\331\336\332\351\333\353\334\232\335\355\336\335\337\341"); +update_map("\340\352\341\240\342\203\343\307\344\204\345\222\346\206\347\207"); +update_map("\350\237\351\202\352\251\353\211\354\330\355\241\356\214\357\324"); +update_map("\360\320\361\344\362\345\363\242\364\223\365\213\366\224\367\366"); +update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372"); } /* Init for russian language (iso8859-5) */ -- cgit From 4bd1feb68c4f5134293d87433da932c20cded915 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Nov 1998 18:40:51 +0000 Subject: lib/charcnv.c: Improved debug comment. libsmb/namequery.c: Fix to remove 2 second wait is we are doing a unicast and got a reply. smbd/dfree.c: smbd/noquotas.c: smbd/quotas.c: Fixes from Dejan Ilic for the quota code. utils/smbpasswd.c: Fixes to allow smbpasswd to be called from swat. Jeremy. (This used to be commit b5981c0149ad8c6f13ea87db450080616538b5d5) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b016a07fd7..29ef72d7ac 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -225,6 +225,6 @@ void interpret_character_set(char *str) } else if (strequal (str, "koi8-r")) { init_koi8_r(); } else { - DEBUG(0,("unrecognized character set\n")); + DEBUG(0,("unrecognized character set %s\n", str)); } } -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/lib/charcnv.c | 204 +++++++++++++++++++++++++++++++------------------- 1 file changed, 129 insertions(+), 75 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 29ef72d7ac..8f91e4573a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -23,7 +23,7 @@ #define CTRLZ 26 extern int DEBUGLEVEL; -static char cvtbuf[1024]; +static char cvtbuf[sizeof(pstring)]; static BOOL mapsinited = 0; @@ -39,7 +39,7 @@ static void initmaps(void) { mapsinited = True; } -static void update_map(char * str) { +static void update_map(char *str) { char *p; for (p = str; *p; p++) { @@ -51,47 +51,55 @@ static void update_map(char * str) { } } -static void init_iso8859_1(void) { - +static void setupmaps(void) +{ int i; if (!mapsinited) initmaps(); /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) + for (i = 128; i < 256; i++) { unix2dos[i] = CTRLZ; dos2unix[i] = CTRLZ; } +} -/* MSDOS Code Page 850 -> ISO-8859 */ -update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); -update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); -update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); -update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); -update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); -update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); -update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); -update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); -update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); -update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); -update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); -update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); +static void init_iso8859_1(int codepage) { + setupmaps(); + + if (codepage == 437) { + /* MSDOS Code Page 437 -> ISO-8859-1 */ + update_map("\xA1\xAD\xA2\x98\xA3\x9C\xA4\xED\xA5\x9D\xA6\xB3\xA7\xEE"); + update_map("\xAA\xA6\xAB\xAE\xAC\xAA\xAE\xE9\xAF\xC4"); + update_map("\xB0\xF8\xB1\xF1\xB2\xFD\xB5\xE6\xB7\xFA\xBA\xA7\xBC\xAC\xBD\xAB\xBF\xA8"); + update_map("\xC0\x85\xC1\xA0\xC2\x83\xC4\x8E\xC5\x8F\xC6\x92\xC7\x80\xC8\x8A"); + update_map("\xC9\x90\xCA\x88\xCB\x89\xCC\x8D\xCD\xA1\xCE\x8C\xCF\x8B"); + update_map("\xD1\xA5\xD2\x96\xD3\xA2\xD4\x93\xD6\x99\xD9\x97\xDA\xA3\xDB\x96\xDC\x9A\xDF\xE1"); + update_map("\xE0\x85\xE1\xA0\xE2\x83\xE4\x84\xE5\x86\xE6\x91\xE7\x87\xE8\x8A\xE9\x82\xEA\x88\xEB\x89\xEC\x8D\xED\xA1\xEE\x8C\xEF\x8B"); + update_map("\xF0\xEB\xF1\xA4\xF2\x95\xF3\xA2\xF4\x93\xF6\x94\xF7\xF6\xF8\xED\xF9\x97\xFA\xA3\xFB\x96\xFC\x81\xFF\x98"); + } else { + /* MSDOS Code Page 850 -> ISO-8859-1 */ + update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); + update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); + update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); + update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); + update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); + update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); + update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); + update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); + update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); + update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); + update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); + update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); + } } /* Init for eastern european languages. */ static void init_iso8859_2(void) { - int i; - if (!mapsinited) initmaps(); - - /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) - { - unix2dos[i] = CTRLZ; - dos2unix[i] = CTRLZ; - } + setupmaps(); /* * Tranlation table created by Petr Hubeny @@ -120,36 +128,48 @@ update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372"); static void init_iso8859_5(void) { - int i; - if (!mapsinited) initmaps(); - - /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) - { - unix2dos[i] = CTRLZ; - dos2unix[i] = CTRLZ; - } + setupmaps(); /* MSDOS Code Page 866 -> ISO8859-5 */ -update_map("\200\260\201\261\202\262\203\263\204\264\205\265\206\266\207\267"); -update_map("\210\270\211\271\212\272\213\273\214\274\215\275\216\276\217\277"); -update_map("\220\300\221\301\222\302\223\303\224\304\225\305\226\306\227\307"); -update_map("\230\310\231\311\232\312\233\313\234\314\235\315\236\316\237\317"); -update_map("\240\320\241\321\242\322\243\323\244\324\245\325\246\326\247\327"); -update_map("\250\330\251\331\252\332\253\333\254\334\255\335\256\336\257\337"); +update_map("\260\200\261\201\262\202\263\203\264\204\265\205\266\206\267\207"); +update_map("\270\210\271\211\272\212\273\213\274\214\275\215\276\216\277\217"); +update_map("\300\220\301\221\302\222\303\223\304\224\305\225\306\226\307\227"); +update_map("\310\230\311\231\312\232\313\233\314\234\315\235\316\236\317\237"); +update_map("\320\240\321\241\322\242\323\243\324\244\325\245\326\246\327\247"); +update_map("\330\250\331\251\332\252\333\253\334\254\335\255\336\256\337\257"); update_map("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347"); update_map("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357"); -update_map("\360\241\361\361\362\244\363\364\364\247\365\367\366\256\367\376"); -update_map("\374\360\377\240"); +update_map("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367"); +update_map("\360\374\240\377"); +} + +/* Added by Antonios Kavarnos (Antonios.Kavarnos@softlab.ece.ntua.gr */ + +static void init_iso8859_7(void) +{ + setupmaps(); + +/* MSDOS Code Page 737 -> ISO-8859-7 (Greek-Hellenic) */ + +update_map("\301\200\302\201\303\202\304\203\305\204\306\205\307\206"); +update_map("\310\207\311\210\312\211\313\212\314\213\315\214\316\215\317\216"); +update_map("\320\217\321\220\323\221\324\222\325\223\326\224\327\225"); +update_map("\330\226\331\227"); +update_map("\341\230\342\231\343\232\344\233\345\234\346\235\347\236"); +update_map("\350\237\351\240\352\241\353\242\354\243\355\244\356\245\357\246"); +update_map("\360\247\361\250\362\252\363\251\364\253\365\254\366\255\367\256"); +update_map("\370\257\371\340"); +update_map("\332\364\333\365\334\341\335\342\336\343\337\345"); +update_map("\372\344\373\350\374\346\375\347\376\351"); +update_map("\266\352"); +update_map("\270\353\271\354\272\355\274\356\276\357\277\360"); } /* Init for russian language (koi8) */ static void init_koi8_r(void) { - if (!mapsinited) initmaps(); - - /* There aren't undefined characters between 128 and 255 */ + setupmaps(); /* MSDOS Code Page 866 -> KOI8-R */ update_map("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264"); @@ -170,24 +190,49 @@ update_map("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202"); update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232"); } + +/* Init for ROMAN-8 (HP-UX) */ + +static void init_roman8(void) { + + setupmaps(); + +/* MSDOS Code Page 850 -> ROMAN8 */ +update_map("\240\377\241\267\242\266\243\324\244\322\245\323\246\327\247\330"); +update_map("\250\357\253\371\255\353\256\352\257\234"); +update_map("\260\356\261\355\262\354\263\370\264\200\265\207\266\245\267\244"); +update_map("\270\255\271\250\272\317\273\234\274\276\275\365\276\237\277\275"); +update_map("\300\203\301\210\302\223\303\226\304\240\305\202\306\242\307\243"); +update_map("\310\205\311\212\312\225\313\227\314\204\315\211\316\224\317\201"); +update_map("\320\217\321\214\322\235\323\222\324\206\325\241\326\233\327\221"); +update_map("\330\216\331\215\332\231\333\232\334\220\335\213\336\341\337\342"); +update_map("\340\265\341\307\342\306\343\321\344\320\345\326\346\336\347\340"); +update_map("\350\343\351\345\352\344\355\351\357\230"); +update_map("\360\350\361\347\362\372\363\346\364\364\365\363\366\360\367\254"); +update_map("\370\253\371\246\372\247\373\256\374\376\375\257\376\361"); +} + /* * Convert unix to dos */ char *unix2dos_format(char *str,BOOL overwrite) { - char *p; - char *dp; - - if (!mapsinited) initmaps(); - - if (overwrite) { - for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + char *p; + char *dp; + + if (!mapsinited) + initmaps(); + + if (overwrite) { + for (p = str; *p; p++) + *p = unix2dos[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) + *dp = unix2dos[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } /* @@ -195,36 +240,45 @@ char *unix2dos_format(char *str,BOOL overwrite) */ char *dos2unix_format(char *str, BOOL overwrite) { - char *p; - char *dp; - - if (!mapsinited) initmaps(); - - if (overwrite) { - for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + char *p; + char *dp; + + if (!mapsinited) + initmaps(); + + if (overwrite) { + for (p = str; *p; p++) + *p = dos2unix[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) + *dp = dos2unix[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } /* * Interpret character set. */ -void interpret_character_set(char *str) +void interpret_character_set(char *str, int codepage) { if (strequal (str, "iso8859-1")) { - init_iso8859_1(); + init_iso8859_1(codepage); } else if (strequal (str, "iso8859-2")) { init_iso8859_2(); } else if (strequal (str, "iso8859-5")) { init_iso8859_5(); + } else if (strequal (str, "iso8859-7")) { + init_iso8859_7(); } else if (strequal (str, "koi8-r")) { init_koi8_r(); + } else if (strequal (str, "roman8")) { + init_roman8(); } else { DEBUG(0,("unrecognized character set %s\n", str)); } + + load_unix_unicode_map(str); } -- cgit From 1a27ef121a020cba88bf4a39959c7f299a7155ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Feb 2000 03:11:22 +0000 Subject: Fixes for Eastern Europe code page. Jeremy. (This used to be commit 0ec82d661a27a02322e5c8da20a18f33bfb24a3e) --- source3/lib/charcnv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 8f91e4573a..2916f0ceda 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -108,6 +108,7 @@ static void init_iso8859_2(void) { */ /* MSDOS Code Page 852 -> ISO-8859-2 */ +update_map("\240\377"); /* Fix for non-breaking space */ update_map("\241\244\242\364\243\235\244\317\245\225\246\227\247\365"); update_map("\250\371\251\346\252\270\253\233\254\215\256\246\257\275"); update_map("\261\245\262\362\263\210\264\357\265\226\266\230\267\363"); -- cgit From 6b51372c2e6cc0e7eba36c677d92c6617c67ef72 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 7 Jan 2001 23:00:49 +0000 Subject: Codepages and stuff for Turkish language support. Contributed by Deniz Akkus (This used to be commit 5650c143a706a0a65dfd55dea2248c6636a57912) --- source3/lib/charcnv.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2916f0ceda..a5355aa7c8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -166,6 +166,29 @@ update_map("\266\352"); update_map("\270\353\271\354\272\355\274\356\276\357\277\360"); } +/* Added by Deniz Akkus (akkus@alum.mit.edu) */ + +static void init_iso8859_9(void) +{ + setupmaps(); + + /* MSDOS Code Page 857 -> ISO-8859-9 (Turkish) */ + + update_map("\xa0\xff\xa1\xad\xa2\xbd\xa3\x9c\xa4\xcf\xA5\xbe\xa6\xdd\xa7\xf5"); + update_map("\xa8\xf9\xa9\xb8\xaa\xd1\xab\xae\xac\xaa\xad\xf0\xae\xa9\xaf\xee"); + update_map("\xb0\xf8\xb1\xf1\xb2\xfd\xb3\xfc\xb4\xef\xb5\xe6\xb6\xf4\xb7\xfa"); + update_map("\xb8\xf7\xb9\xfb\xba\xd0\xbb\xaf\xbc\xac\xbd\xab\xbe\xf3\xbf\xa8"); + update_map("\xc0\xb7\xc1\xb5\xc2\xb6\xc3\xc7\xc4\x8e\xc5\x8f\xc6\x92\xc7\x80"); + update_map("\xc8\xd4\xc9\x90\xca\xd2\xcb\xd3\xcc\xde\xcd\xd6\xce\xd7\xcf\xd8"); + update_map("\xd0\xa6\xd1\xa5\xd2\xe3\xd3\xe0\xd4\xe2\xd5\xe5\xd6\x99\xd7\xe8"); + update_map("\xd8\x9d\xd9\xeb\xda\xe9\xdb\xea\xdc\x9a\xdd\x98\xde\x9e\xdf\xe1"); + update_map("\xe0\x85\xe1\xa0\xe2\x83\xe3\xc6\xe4\x84\xe5\x86\xe6\x91\xe7\x87"); + update_map("\xe8\x8a\xe9\x82\xea\x88\xeb\x89\xec\xec\xed\xa1\xee\x8c\xef\x8b"); + update_map("\xf0\xa7\xf1\xa4\xf2\x95\xf3\xa2\xf4\x93\xf5\xe4\xf6\x94\xf7\xf6"); + update_map("\xf8\x9b\xf9\x97\xfa\xa3\xfb\x96\xfc\x81\xfd\x8d\xfe\x9f\xff\xed"); +} + + /* Init for russian language (koi8) */ static void init_koi8_r(void) @@ -273,6 +296,8 @@ void interpret_character_set(char *str, int codepage) init_iso8859_5(); } else if (strequal (str, "iso8859-7")) { init_iso8859_7(); + } else if (strequal (str, "iso8859-9")) { + init_iso8859_9(); } else if (strequal (str, "koi8-r")) { init_koi8_r(); } else if (strequal (str, "roman8")) { -- cgit From 09b993ff4690e8036aab7bb45343b54fdd6976e7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 14 Feb 2001 21:56:57 +0000 Subject: Baltic codepage fixes from Toomas Soome (This used to be commit 1f1fcea06d658375b234bbfedcabcedd01c66a88) --- source3/lib/charcnv.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a5355aa7c8..7fedc282ba 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -19,7 +19,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "includes.h" + #define CTRLZ 26 extern int DEBUGLEVEL; @@ -95,6 +97,42 @@ static void init_iso8859_1(int codepage) { } } +static void init_iso8859_15(int codepage) { + + setupmaps(); + + + if (codepage == 775) { + /* MSDOS Code Page 775 -> ISO-8859-15 this is for estonian */ +update_map("\240\377\242\226\243\234\246\276\247\365"); +update_map("\250\325\251\250\253\256\254\252\255\360\256\251"); +update_map("\260\370\261\361\262\375\263\374\264\317\265\346\266\364\267\372"); +update_map("\270\330\271\373\273\257"); +update_map("\304\216\305\217\306\222"); +update_map("\311\220"); +update_map("\323\340\325\345\326\231\327\236"); +update_map("\330\235\334\232\337\341"); +update_map("\344\204\345\206\346\221"); +update_map("\351\202"); +update_map("\363\242\365\344\366\224\367\366"); +update_map("\370\233\374\201"); + } else { + /* MSDOS Code Page 850 -> ISO-8859-15 */ +update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\321\247\365"); +update_map("\250\320\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); +update_map("\260\370\261\361\262\375\263\374\264\350\265\346\266\364\267\372"); +update_map("\270\347\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); +update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); +update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); +update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); +update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); +update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); +update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); +update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); +update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); +} +} + /* Init for eastern european languages. */ static void init_iso8859_2(void) { @@ -188,6 +226,26 @@ static void init_iso8859_9(void) update_map("\xf8\x9b\xf9\x97\xfa\xa3\xfb\x96\xfc\x81\xfd\x8d\xfe\x9f\xff\xed"); } +/* init for Baltic Rim */ + +static void init_iso8859_13(void) { + + setupmaps(); + + /* MSDOS Code Page 775 -> ISO-8859-13 */ +update_map("\240\377\241\246\242\226\243\234\244\237\245\367\246\247\247\365"); +update_map("\250\235\251\250\252\212\253\256\254\252\255\360\256\251\257\222"); +update_map("\260\370\261\361\262\375\263\374\264\362\265\346\266\364\267\372"); +update_map("\270\233\271\373\272\213\273\257\274\254\275\253\276\363\277\221"); +update_map("\300\265\301\275\302\240\303\200\304\216\305\217\306\267\307\355"); +update_map("\310\266\311\220\312\215\313\270\314\225\315\350\316\241\317\352"); +update_map("\320\276\321\343\322\356\323\340\324\342\325\345\326\231\327\236"); +update_map("\330\306\331\255\332\227\333\307\334\232\335\243\336\317\337\341"); +update_map("\340\320\341\324\342\203\343\207\344\204\345\206\346\322\347\211"); +update_map("\350\321\351\202\352\245\353\323\354\205\355\351\356\214\357\353"); +update_map("\360\325\361\347\362\354\363\242\364\223\365\344\366\224\367\366"); +update_map("\370\326\371\210\372\230\373\327\374\201\375\244\376\330\377\357"); +} /* Init for russian language (koi8) */ @@ -298,6 +356,10 @@ void interpret_character_set(char *str, int codepage) init_iso8859_7(); } else if (strequal (str, "iso8859-9")) { init_iso8859_9(); + } else if (strequal (str, "iso8859-13")) { + init_iso8859_13(); + } else if (strequal (str, "iso8859-15")) { + init_iso8859_15(codepage); } else if (strequal (str, "koi8-r")) { init_koi8_r(); } else if (strequal (str, "roman8")) { -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/lib/charcnv.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7fedc282ba..4a3d7090e3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -19,9 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - #include "includes.h" - #define CTRLZ 26 extern int DEBUGLEVEL; -- cgit 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/charcnv.c | 584 ++++++++++++++++++++++++-------------------------- 1 file changed, 285 insertions(+), 299 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4a3d7090e3..388c05f816 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1,8 +1,9 @@ /* Unix SMB/Netbios implementation. - Version 1.9. + Version 3.0 Character set conversion Extensions - Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Igor Vergeichik 2001 + 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 @@ -20,351 +21,336 @@ */ #include "includes.h" -#define CTRLZ 26 + extern int DEBUGLEVEL; -static char cvtbuf[sizeof(pstring)]; +static pstring cvtbuf; -static BOOL mapsinited = 0; +static smb_iconv_t + ucs2_to_unix=(smb_iconv_t)-1, /*ucs2 (MS) <-> unix format */ + unix_to_ucs2=(smb_iconv_t)-1, + dos_to_unix=(smb_iconv_t)-1, /*unix format <-> dos codepage*/ + unix_to_dos=(smb_iconv_t)-1; /*for those clients who does not support unicode*/ -static char unix2dos[256]; -static char dos2unix[256]; + +/**************************************************************************** + Initialize iconv conversion descriptors +****************************************************************************/ +void init_iconv(char *unix_charset, char *dos_charset) +{ +#define ICONV(descr, from_name, to_name)\ + if(descr!=(smb_iconv_t)-1) smb_iconv_close(descr);\ + descr = smb_iconv_open(to_name, from_name);\ + if(descr==(smb_iconv_t)-1)\ + DEBUG(0,("Conversion from %s to %s is not supported\n",from_name,to_name)); + + if (!unix_charset || !*unix_charset) unix_charset = "ASCII"; + if (!dos_charset || !*dos_charset) dos_charset = "ASCII"; + + ICONV(ucs2_to_unix, "UCS2", unix_charset) + ICONV(unix_to_ucs2, unix_charset, "UCS2") + ICONV(dos_to_unix, dos_charset, unix_charset) + ICONV(unix_to_dos, unix_charset, dos_charset) + +#undef ICONV +} -static void initmaps(void) { - int k; +/**************************************************************************** + Convert string from one encoding to another, makeing error checking etc + Parameters: + descriptor - conversion descriptor, created in init_iconv + src - pointer to source string (multibute or singlebyte) + srclen - length of the source string in bytes + dest - pointer to destination string (multibyte or singlebyte) + destlen - maximal length allowed for string +return the number of bytes occupied in the destination +****************************************************************************/ +static size_t convert_string(smb_iconv_t descriptor, + void const *src, size_t srclen, + void *dest, size_t destlen) +{ + size_t i_len, o_len; + size_t retval; + char* inbuf = (char*)src; + char* outbuf = (char*)dest; + + if (descriptor == (smb_iconv_t)-1) { + /* conversion not supported, use as is */ + int len = MIN(srclen,destlen); + memcpy(dest,src,len); + return len; + } + + i_len=srclen; + o_len=destlen; + retval=smb_iconv(descriptor,&inbuf, &i_len, &outbuf, &o_len); + if(retval==-1) + { char *reason; + switch(errno) + { case EINVAL: reason="Incomplete multybyte sequence"; break; + case E2BIG: reason="No more room"; + DEBUG(0, ("Required %d, available %d\n", + srclen, destlen)); + break; + case EILSEQ: reason="Illegal myltybyte sequence"; break; + } + DEBUG(0,("Conversion error:%s(%s)\n",reason,inbuf)); + /* smb_panic(reason); */ + } + return destlen-o_len; +} - for (k = 0; k < 256; k++) unix2dos[k] = k; - for (k = 0; k < 256; k++) dos2unix[k] = k; +int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) +{ + int size,len; + smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; + size=convert_string(unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); + len=size/2; + strupper_w(buffer); + return convert_string(ucs2_to_unix, buffer, size, dest, destlen); +} - mapsinited = True; +int unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) +{ + int size,len; + smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; + size=convert_string(unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); + len=size/2; + strlower_w(buffer); + return convert_string(ucs2_to_unix, buffer, size, dest, destlen); } -static void update_map(char *str) { - char *p; - for (p = str; *p; p++) { - if (p[1]) { - unix2dos[(unsigned char)*p] = p[1]; - dos2unix[(unsigned char)p[1]] = *p; - p++; - } - } +int ucs2_align(const void *base_ptr, const void *p, int flags) +{ + if (flags & (STR_NOALIGN|STR_ASCII)) return 0; + return PTR_DIFF(p, base_ptr) & 1; } -static void setupmaps(void) + +/**************************************************************************** +copy a string from a char* unix src to a dos codepage string destination +return the number of bytes occupied by the string in the destination +flags can have: + STR_TERMINATE means include the null termination + STR_UPPER means uppercase in the destination +dest_len is the maximum length allowed in the destination. If dest_len +is -1 then no maxiumum is used +****************************************************************************/ +int push_ascii(void *dest, const char *src, int dest_len, int flags) { - int i; - if (!mapsinited) initmaps(); - - /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) - { - unix2dos[i] = CTRLZ; - dos2unix[i] = CTRLZ; - } -} + int src_len = strlen(src); + pstring tmpbuf; -static void init_iso8859_1(int codepage) { - - setupmaps(); - - if (codepage == 437) { - /* MSDOS Code Page 437 -> ISO-8859-1 */ - update_map("\xA1\xAD\xA2\x98\xA3\x9C\xA4\xED\xA5\x9D\xA6\xB3\xA7\xEE"); - update_map("\xAA\xA6\xAB\xAE\xAC\xAA\xAE\xE9\xAF\xC4"); - update_map("\xB0\xF8\xB1\xF1\xB2\xFD\xB5\xE6\xB7\xFA\xBA\xA7\xBC\xAC\xBD\xAB\xBF\xA8"); - update_map("\xC0\x85\xC1\xA0\xC2\x83\xC4\x8E\xC5\x8F\xC6\x92\xC7\x80\xC8\x8A"); - update_map("\xC9\x90\xCA\x88\xCB\x89\xCC\x8D\xCD\xA1\xCE\x8C\xCF\x8B"); - update_map("\xD1\xA5\xD2\x96\xD3\xA2\xD4\x93\xD6\x99\xD9\x97\xDA\xA3\xDB\x96\xDC\x9A\xDF\xE1"); - update_map("\xE0\x85\xE1\xA0\xE2\x83\xE4\x84\xE5\x86\xE6\x91\xE7\x87\xE8\x8A\xE9\x82\xEA\x88\xEB\x89\xEC\x8D\xED\xA1\xEE\x8C\xEF\x8B"); - update_map("\xF0\xEB\xF1\xA4\xF2\x95\xF3\xA2\xF4\x93\xF6\x94\xF7\xF6\xF8\xED\xF9\x97\xFA\xA3\xFB\x96\xFC\x81\xFF\x98"); - } else { - /* MSDOS Code Page 850 -> ISO-8859-1 */ - update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); - update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); - update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); - update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); - update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); - update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); - update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); - update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); - update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); - update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); - update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); - update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); - } -} + /* treat a pstring as "unlimited" length */ + if (dest_len == -1) { + dest_len = sizeof(pstring); + } -static void init_iso8859_15(int codepage) { - - setupmaps(); - - - if (codepage == 775) { - /* MSDOS Code Page 775 -> ISO-8859-15 this is for estonian */ -update_map("\240\377\242\226\243\234\246\276\247\365"); -update_map("\250\325\251\250\253\256\254\252\255\360\256\251"); -update_map("\260\370\261\361\262\375\263\374\264\317\265\346\266\364\267\372"); -update_map("\270\330\271\373\273\257"); -update_map("\304\216\305\217\306\222"); -update_map("\311\220"); -update_map("\323\340\325\345\326\231\327\236"); -update_map("\330\235\334\232\337\341"); -update_map("\344\204\345\206\346\221"); -update_map("\351\202"); -update_map("\363\242\365\344\366\224\367\366"); -update_map("\370\233\374\201"); - } else { - /* MSDOS Code Page 850 -> ISO-8859-15 */ -update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\321\247\365"); -update_map("\250\320\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); -update_map("\260\370\261\361\262\375\263\374\264\350\265\346\266\364\267\372"); -update_map("\270\347\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); -update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); -update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); -update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); -update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); -update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); -update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); -update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); -update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); -} -} + if (flags & STR_UPPER) { + pstrcpy(tmpbuf, src); + strupper(tmpbuf); + src = tmpbuf; + } -/* Init for eastern european languages. */ - -static void init_iso8859_2(void) { - - setupmaps(); - -/* - * Tranlation table created by Petr Hubeny - * Requires client code page = 852 - * and character set = ISO8859-2 in smb.conf - */ - -/* MSDOS Code Page 852 -> ISO-8859-2 */ -update_map("\240\377"); /* Fix for non-breaking space */ -update_map("\241\244\242\364\243\235\244\317\245\225\246\227\247\365"); -update_map("\250\371\251\346\252\270\253\233\254\215\256\246\257\275"); -update_map("\261\245\262\362\263\210\264\357\265\226\266\230\267\363"); -update_map("\270\367\271\347\272\255\273\234\274\253\275\361\276\247\277\276"); -update_map("\300\350\301\265\302\266\303\306\304\216\305\221\306\217\307\200"); -update_map("\310\254\311\220\312\250\313\323\314\267\315\326\316\327\317\322"); -update_map("\320\321\321\343\322\325\323\340\324\342\325\212\326\231\327\236"); -update_map("\330\374\331\336\332\351\333\353\334\232\335\355\336\335\337\341"); -update_map("\340\352\341\240\342\203\343\307\344\204\345\222\346\206\347\207"); -update_map("\350\237\351\202\352\251\353\211\354\330\355\241\356\214\357\324"); -update_map("\360\320\361\344\362\345\363\242\364\223\365\213\366\224\367\366"); -update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372"); + if (flags & STR_TERMINATE) { + src_len++; + } + + return convert_string(unix_to_dos, src, src_len, dest, dest_len); } -/* Init for russian language (iso8859-5) */ +int push_ascii_fstring(void *dest, const char *src) +{ + return push_ascii(dest, src, sizeof(fstring), STR_TERMINATE); +} -/* Added by Max Khon */ +int push_ascii_pstring(void *dest, const char *src) +{ + return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); +} -static void init_iso8859_5(void) +int push_pstring(void *dest, const char *src) { - setupmaps(); - -/* MSDOS Code Page 866 -> ISO8859-5 */ -update_map("\260\200\261\201\262\202\263\203\264\204\265\205\266\206\267\207"); -update_map("\270\210\271\211\272\212\273\213\274\214\275\215\276\216\277\217"); -update_map("\300\220\301\221\302\222\303\223\304\224\305\225\306\226\307\227"); -update_map("\310\230\311\231\312\232\313\233\314\234\315\235\316\236\317\237"); -update_map("\320\240\321\241\322\242\323\243\324\244\325\245\326\246\327\247"); -update_map("\330\250\331\251\332\252\333\253\334\254\335\255\336\256\337\257"); -update_map("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347"); -update_map("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357"); -update_map("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367"); -update_map("\360\374\240\377"); + return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } -/* Added by Antonios Kavarnos (Antonios.Kavarnos@softlab.ece.ntua.gr */ -static void init_iso8859_7(void) +/**************************************************************************** +copy a string from a dos codepage source to a unix char* destination +flags can have: + STR_TERMINATE means the string in src is null terminated +if STR_TERMINATE is set then src_len is ignored +src_len is the length of the source area in bytes +return the number of bytes occupied by the string in src +the resulting string in "dest" is always null terminated +****************************************************************************/ +int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags) { - setupmaps(); - -/* MSDOS Code Page 737 -> ISO-8859-7 (Greek-Hellenic) */ - -update_map("\301\200\302\201\303\202\304\203\305\204\306\205\307\206"); -update_map("\310\207\311\210\312\211\313\212\314\213\315\214\316\215\317\216"); -update_map("\320\217\321\220\323\221\324\222\325\223\326\224\327\225"); -update_map("\330\226\331\227"); -update_map("\341\230\342\231\343\232\344\233\345\234\346\235\347\236"); -update_map("\350\237\351\240\352\241\353\242\354\243\355\244\356\245\357\246"); -update_map("\360\247\361\250\362\252\363\251\364\253\365\254\366\255\367\256"); -update_map("\370\257\371\340"); -update_map("\332\364\333\365\334\341\335\342\336\343\337\345"); -update_map("\372\344\373\350\374\346\375\347\376\351"); -update_map("\266\352"); -update_map("\270\353\271\354\272\355\274\356\276\357\277\360"); + int ret; + + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (flags & STR_TERMINATE) src_len = strlen(src)+1; + + ret = convert_string(dos_to_unix, src, src_len, dest, dest_len); + + if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + + return src_len; } -/* Added by Deniz Akkus (akkus@alum.mit.edu) */ +int pull_ascii_pstring(char *dest, const void *src) +{ + return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE); +} -static void init_iso8859_9(void) +int pull_ascii_fstring(char *dest, const void *src) { - setupmaps(); - - /* MSDOS Code Page 857 -> ISO-8859-9 (Turkish) */ - - update_map("\xa0\xff\xa1\xad\xa2\xbd\xa3\x9c\xa4\xcf\xA5\xbe\xa6\xdd\xa7\xf5"); - update_map("\xa8\xf9\xa9\xb8\xaa\xd1\xab\xae\xac\xaa\xad\xf0\xae\xa9\xaf\xee"); - update_map("\xb0\xf8\xb1\xf1\xb2\xfd\xb3\xfc\xb4\xef\xb5\xe6\xb6\xf4\xb7\xfa"); - update_map("\xb8\xf7\xb9\xfb\xba\xd0\xbb\xaf\xbc\xac\xbd\xab\xbe\xf3\xbf\xa8"); - update_map("\xc0\xb7\xc1\xb5\xc2\xb6\xc3\xc7\xc4\x8e\xc5\x8f\xc6\x92\xc7\x80"); - update_map("\xc8\xd4\xc9\x90\xca\xd2\xcb\xd3\xcc\xde\xcd\xd6\xce\xd7\xcf\xd8"); - update_map("\xd0\xa6\xd1\xa5\xd2\xe3\xd3\xe0\xd4\xe2\xd5\xe5\xd6\x99\xd7\xe8"); - update_map("\xd8\x9d\xd9\xeb\xda\xe9\xdb\xea\xdc\x9a\xdd\x98\xde\x9e\xdf\xe1"); - update_map("\xe0\x85\xe1\xa0\xe2\x83\xe3\xc6\xe4\x84\xe5\x86\xe6\x91\xe7\x87"); - update_map("\xe8\x8a\xe9\x82\xea\x88\xeb\x89\xec\xec\xed\xa1\xee\x8c\xef\x8b"); - update_map("\xf0\xa7\xf1\xa4\xf2\x95\xf3\xa2\xf4\x93\xf5\xe4\xf6\x94\xf7\xf6"); - update_map("\xf8\x9b\xf9\x97\xfa\xa3\xfb\x96\xfc\x81\xfd\x8d\xfe\x9f\xff\xed"); + return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } -/* init for Baltic Rim */ - -static void init_iso8859_13(void) { - - setupmaps(); - - /* MSDOS Code Page 775 -> ISO-8859-13 */ -update_map("\240\377\241\246\242\226\243\234\244\237\245\367\246\247\247\365"); -update_map("\250\235\251\250\252\212\253\256\254\252\255\360\256\251\257\222"); -update_map("\260\370\261\361\262\375\263\374\264\362\265\346\266\364\267\372"); -update_map("\270\233\271\373\272\213\273\257\274\254\275\253\276\363\277\221"); -update_map("\300\265\301\275\302\240\303\200\304\216\305\217\306\267\307\355"); -update_map("\310\266\311\220\312\215\313\270\314\225\315\350\316\241\317\352"); -update_map("\320\276\321\343\322\356\323\340\324\342\325\345\326\231\327\236"); -update_map("\330\306\331\255\332\227\333\307\334\232\335\243\336\317\337\341"); -update_map("\340\320\341\324\342\203\343\207\344\204\345\206\346\322\347\211"); -update_map("\350\321\351\202\352\245\353\323\354\205\355\351\356\214\357\353"); -update_map("\360\325\361\347\362\354\363\242\364\223\365\344\366\224\367\366"); -update_map("\370\326\371\210\372\230\373\327\374\201\375\244\376\330\377\357"); +/**************************************************************************** +copy a string from a char* src to a unicode destination +return the number of bytes occupied by the string in the destination +flags can have: + STR_TERMINATE means include the null termination + STR_UPPER means uppercase in the destination + STR_NOALIGN means don't do alignment +dest_len is the maximum length allowed in the destination. If dest_len +is -1 then no maxiumum is used +****************************************************************************/ +int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) +{ + int len=0; + int src_len = strlen(src); + pstring tmpbuf; + + /* treat a pstring as "unlimited" length */ + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (flags & STR_UPPER) { + pstrcpy(tmpbuf, src); + strupper(tmpbuf); + src = tmpbuf; + } + + if (flags & STR_TERMINATE) { + src_len++; + } + + if (ucs2_align(base_ptr, dest, flags)) { + *(char *)dest = 0; + dest = (void *)((char *)dest + 1); + if (dest_len) dest_len--; + len++; + } + + len += convert_string(unix_to_ucs2, src, src_len, dest, dest_len); + return len; } -/* Init for russian language (koi8) */ -static void init_koi8_r(void) +/**************************************************************************** +copy a string from a ucs2 source to a unix char* destination +flags can have: + STR_TERMINATE means the string in src is null terminated + STR_NOALIGN means don't try to align +if STR_TERMINATE is set then src_len is ignored +src_len is the length of the source area in bytes +return the number of bytes occupied by the string in src +the resulting string in "dest" is always null terminated +****************************************************************************/ +int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, int flags) { - setupmaps(); - -/* MSDOS Code Page 866 -> KOI8-R */ -update_map("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264"); -update_map("\210\302\211\301\212\305\213\337\214\334\215\333\216\335\217\336"); -update_map("\220\260\221\261\222\262\223\364\224\376\225\371\226\373\227\367"); -update_map("\230\363\231\362\232\377\233\365\234\370\235\375\236\372\237\366"); -update_map("\240\315\241\272\242\325\243\361\244\326\245\311\246\270\247\267"); -update_map("\250\273\251\324\252\323\253\310\254\276\255\275\256\274\257\306"); -update_map("\260\307\261\314\262\265\263\360\264\266\265\271\266\321\267\322"); -update_map("\270\313\271\317\272\320\273\312\274\330\275\327\276\316\277\374"); -update_map("\300\356\301\240\302\241\303\346\304\244\305\245\306\344\307\243"); -update_map("\310\345\311\250\312\251\313\252\314\253\315\254\316\255\317\256"); -update_map("\320\257\321\357\322\340\323\341\324\342\325\343\326\246\327\242"); -update_map("\330\354\331\353\332\247\333\350\334\355\335\351\336\347\337\352"); -update_map("\340\236\341\200\342\201\343\226\344\204\345\205\346\224\347\203"); -update_map("\350\225\351\210\352\211\353\212\354\213\355\214\356\215\357\216"); -update_map("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202"); -update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232"); -} + int ret; + + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + if (ucs2_align(base_ptr, src, flags)) { + src = (const void *)((const char *)src + 1); + if (src_len > 0) src_len--; + } -/* Init for ROMAN-8 (HP-UX) */ + if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; -static void init_roman8(void) { + ret = convert_string(ucs2_to_unix, src, src_len, dest, dest_len); + if (dest_len) dest[MIN(ret, dest_len-1)] = 0; - setupmaps(); + return src_len; +} -/* MSDOS Code Page 850 -> ROMAN8 */ -update_map("\240\377\241\267\242\266\243\324\244\322\245\323\246\327\247\330"); -update_map("\250\357\253\371\255\353\256\352\257\234"); -update_map("\260\356\261\355\262\354\263\370\264\200\265\207\266\245\267\244"); -update_map("\270\255\271\250\272\317\273\234\274\276\275\365\276\237\277\275"); -update_map("\300\203\301\210\302\223\303\226\304\240\305\202\306\242\307\243"); -update_map("\310\205\311\212\312\225\313\227\314\204\315\211\316\224\317\201"); -update_map("\320\217\321\214\322\235\323\222\324\206\325\241\326\233\327\221"); -update_map("\330\216\331\215\332\231\333\232\334\220\335\213\336\341\337\342"); -update_map("\340\265\341\307\342\306\343\321\344\320\345\326\346\336\347\340"); -update_map("\350\343\351\345\352\344\355\351\357\230"); -update_map("\360\350\361\347\362\372\363\346\364\364\365\363\366\360\367\254"); -update_map("\370\253\371\246\372\247\373\256\374\376\375\257\376\361"); +int pull_ucs2_pstring(char *dest, const void *src) +{ + return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); } -/* - * Convert unix to dos - */ -char *unix2dos_format(char *str,BOOL overwrite) +int pull_ucs2_fstring(char *dest, const void *src) { - char *p; - char *dp; - - if (!mapsinited) - initmaps(); - - if (overwrite) { - for (p = str; *p; p++) - *p = unix2dos[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) - *dp = unix2dos[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); } -/* - * Convert dos to unix - */ -char *dos2unix_format(char *str, BOOL overwrite) + +/**************************************************************************** +copy a string from a char* src to a unicode or ascii +dos code page destination choosing unicode or ascii based on the +flags in the SMB buffer starting at base_ptr +return the number of bytes occupied by the string in the destination +flags can have: + STR_TERMINATE means include the null termination + STR_UPPER means uppercase in the destination + STR_ASCII use ascii even with unicode packet + STR_NOALIGN means don't do alignment +dest_len is the maximum length allowed in the destination. If dest_len +is -1 then no maxiumum is used +****************************************************************************/ +int push_string(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) { - char *p; - char *dp; - - if (!mapsinited) - initmaps(); - - if (overwrite) { - for (p = str; *p; p++) - *p = dos2unix[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) - *dp = dos2unix[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + if (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { + return push_ucs2(base_ptr, dest, src, dest_len, flags); + } + return push_ascii(dest, src, dest_len, flags); } -/* - * Interpret character set. - */ -void interpret_character_set(char *str, int codepage) +/**************************************************************************** +copy a string from a unicode or ascii source (depending on +the packet flags) to a char* destination +flags can have: + STR_TERMINATE means the string in src is null terminated + STR_UNICODE means to force as unicode + STR_ASCII use ascii even with unicode packet + STR_NOALIGN means don't do alignment +if STR_TERMINATE is set then src_len is ignored +src_len is the length of the source area in bytes +return the number of bytes occupied by the string in src +the resulting string in "dest" is always null terminated +****************************************************************************/ +int pull_string(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, + int flags) +{ + if (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { + return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags); + } + return pull_ascii(dest, src, dest_len, src_len, flags); +} + +int align_string(const void *base_ptr, const char *p, int flags) { - if (strequal (str, "iso8859-1")) { - init_iso8859_1(codepage); - } else if (strequal (str, "iso8859-2")) { - init_iso8859_2(); - } else if (strequal (str, "iso8859-5")) { - init_iso8859_5(); - } else if (strequal (str, "iso8859-7")) { - init_iso8859_7(); - } else if (strequal (str, "iso8859-9")) { - init_iso8859_9(); - } else if (strequal (str, "iso8859-13")) { - init_iso8859_13(); - } else if (strequal (str, "iso8859-15")) { - init_iso8859_15(codepage); - } else if (strequal (str, "koi8-r")) { - init_koi8_r(); - } else if (strequal (str, "roman8")) { - init_roman8(); - } else { - DEBUG(0,("unrecognized character set %s\n", str)); - } - - load_unix_unicode_map(str); + if (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { + return ucs2_align(base_ptr, p, flags); + } + return 0; } -- cgit From 0225d0c26d8512e72b3fcac4a9e40592f9cb131f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:50:54 +0000 Subject: fixed uninitialised variable (This used to be commit a03992f19b268ca212ada5869c6fc93da5ac3c35) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 388c05f816..154e9971e5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -85,7 +85,7 @@ static size_t convert_string(smb_iconv_t descriptor, o_len=destlen; retval=smb_iconv(descriptor,&inbuf, &i_len, &outbuf, &o_len); if(retval==-1) - { char *reason; + { char *reason="unknown error"; switch(errno) { case EINVAL: reason="Incomplete multybyte sequence"; break; case E2BIG: reason="No more room"; -- 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/charcnv.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 154e9971e5..bec34c0d41 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -92,7 +92,9 @@ static size_t convert_string(smb_iconv_t descriptor, DEBUG(0, ("Required %d, available %d\n", srclen, destlen)); break; +#ifdef EILSEQ case EILSEQ: reason="Illegal myltybyte sequence"; break; +#endif } DEBUG(0,("Conversion error:%s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ -- cgit From c5cc721dc3758d3cec5e3b04078f3b2a52841994 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jul 2001 11:50:07 +0000 Subject: check for initialisation in convert_string() otherwise initial load in smb.conf can fail (This used to be commit e9c53606de237f91712bb9d2a9fdf84b80bce38d) --- source3/lib/charcnv.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index bec34c0d41..30dfd2c504 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -73,6 +73,12 @@ static size_t convert_string(smb_iconv_t descriptor, size_t retval; char* inbuf = (char*)src; char* outbuf = (char*)dest; + static int initialised; + + if (!initialised) { + initialised = 1; + init_iconv(NULL, NULL); + } if (descriptor == (smb_iconv_t)-1) { /* conversion not supported, use as is */ -- cgit From 43dd15913468f35a0d3352530f8e0c403f194521 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 Jul 2001 18:22:04 +0000 Subject: fixed the auto-initialisation of the iconv descriptors (This used to be commit 66632782c583356550446638a832cc46a99f9f62) --- source3/lib/charcnv.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 30dfd2c504..b96c960ec1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -65,7 +65,7 @@ void init_iconv(char *unix_charset, char *dos_charset) destlen - maximal length allowed for string return the number of bytes occupied in the destination ****************************************************************************/ -static size_t convert_string(smb_iconv_t descriptor, +static size_t convert_string(smb_iconv_t *descriptor, void const *src, size_t srclen, void *dest, size_t destlen) { @@ -80,7 +80,7 @@ static size_t convert_string(smb_iconv_t descriptor, init_iconv(NULL, NULL); } - if (descriptor == (smb_iconv_t)-1) { + if (*descriptor == (smb_iconv_t)-1) { /* conversion not supported, use as is */ int len = MIN(srclen,destlen); memcpy(dest,src,len); @@ -89,7 +89,7 @@ static size_t convert_string(smb_iconv_t descriptor, i_len=srclen; o_len=destlen; - retval=smb_iconv(descriptor,&inbuf, &i_len, &outbuf, &o_len); + retval=smb_iconv(*descriptor,&inbuf, &i_len, &outbuf, &o_len); if(retval==-1) { char *reason="unknown error"; switch(errno) @@ -112,20 +112,20 @@ int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { int size,len; smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); + size=convert_string(&unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; strupper_w(buffer); - return convert_string(ucs2_to_unix, buffer, size, dest, destlen); + return convert_string(&ucs2_to_unix, buffer, size, dest, destlen); } int unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { int size,len; smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); + size=convert_string(&unix_to_ucs2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; strlower_w(buffer); - return convert_string(ucs2_to_unix, buffer, size, dest, destlen); + return convert_string(&ucs2_to_unix, buffer, size, dest, destlen); } @@ -165,7 +165,7 @@ int push_ascii(void *dest, const char *src, int dest_len, int flags) src_len++; } - return convert_string(unix_to_dos, src, src_len, dest, dest_len); + return convert_string(&unix_to_dos, src, src_len, dest, dest_len); } int push_ascii_fstring(void *dest, const char *src) @@ -203,7 +203,7 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags if (flags & STR_TERMINATE) src_len = strlen(src)+1; - ret = convert_string(dos_to_unix, src, src_len, dest, dest_len); + ret = convert_string(&dos_to_unix, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -258,7 +258,7 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i len++; } - len += convert_string(unix_to_ucs2, src, src_len, dest, dest_len); + len += convert_string(&unix_to_ucs2, src, src_len, dest, dest_len); return len; } @@ -288,7 +288,7 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; - ret = convert_string(ucs2_to_unix, src, src_len, dest, dest_len); + ret = convert_string(&ucs2_to_unix, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; return src_len; -- 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/charcnv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b96c960ec1..6c7646673d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -32,7 +32,6 @@ static smb_iconv_t dos_to_unix=(smb_iconv_t)-1, /*unix format <-> dos codepage*/ unix_to_dos=(smb_iconv_t)-1; /*for those clients who does not support unicode*/ - /**************************************************************************** Initialize iconv conversion descriptors ****************************************************************************/ @@ -47,8 +46,8 @@ void init_iconv(char *unix_charset, char *dos_charset) if (!unix_charset || !*unix_charset) unix_charset = "ASCII"; if (!dos_charset || !*dos_charset) dos_charset = "ASCII"; - ICONV(ucs2_to_unix, "UCS2", unix_charset) - ICONV(unix_to_ucs2, unix_charset, "UCS2") + ICONV(ucs2_to_unix, "UCS-2LE", unix_charset) + ICONV(unix_to_ucs2, unix_charset, "UCS-2LE") ICONV(dos_to_unix, dos_charset, unix_charset) ICONV(unix_to_dos, unix_charset, dos_charset) -- 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/charcnv.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6c7646673d..49c4ba4063 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -97,9 +97,7 @@ static size_t convert_string(smb_iconv_t *descriptor, DEBUG(0, ("Required %d, available %d\n", srclen, destlen)); break; -#ifdef EILSEQ case EILSEQ: reason="Illegal myltybyte sequence"; break; -#endif } DEBUG(0,("Conversion error:%s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ -- cgit From a9126e5c1caa169cab0133415f668de5d93655e3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Jul 2001 04:00:40 +0000 Subject: ucs2 is always a multiple of 2 bytes this gets rid of a bunch of iconv warnings (This used to be commit 2ec59f731df6489756c5606ed63de90fb2a9241f) --- source3/lib/charcnv.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 49c4ba4063..9bbb8a8507 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -255,6 +255,9 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i len++; } + /* ucs2 is always a multiple of 2 bytes */ + dest_len &= ~1; + len += convert_string(&unix_to_ucs2, src, src_len, dest, dest_len); return len; } @@ -285,6 +288,9 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; + /* ucs2 is always a multiple of 2 bytes */ + src_len &= ~1; + ret = convert_string(&ucs2_to_unix, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; -- 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/charcnv.c | 95 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 34 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9bbb8a8507..ebcceef816 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -26,32 +26,56 @@ extern int DEBUGLEVEL; static pstring cvtbuf; -static smb_iconv_t - ucs2_to_unix=(smb_iconv_t)-1, /*ucs2 (MS) <-> unix format */ - unix_to_ucs2=(smb_iconv_t)-1, - dos_to_unix=(smb_iconv_t)-1, /*unix format <-> dos codepage*/ - unix_to_dos=(smb_iconv_t)-1; /*for those clients who does not support unicode*/ +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; + +/**************************************************************************** +return the name of a charset to give to iconv() +****************************************************************************/ +static char *charset_name(charset_t ch) +{ + char *ret = NULL; + + if (ch == CH_UCS2) ret = "UCS-2LE"; + else if (ch == CH_UNIX) ret = lp_unix_charset(); + else if (ch == CH_DOS) ret = lp_dos_charset(); + else if (ch == CH_DISPLAY) ret = lp_display_charset(); + + if (!ret || !*ret) ret = "ASCII"; + return ret; +} /**************************************************************************** Initialize iconv conversion descriptors ****************************************************************************/ -void init_iconv(char *unix_charset, char *dos_charset) +void init_iconv(void) { -#define ICONV(descr, from_name, to_name)\ - if(descr!=(smb_iconv_t)-1) smb_iconv_close(descr);\ - descr = smb_iconv_open(to_name, from_name);\ - if(descr==(smb_iconv_t)-1)\ - DEBUG(0,("Conversion from %s to %s is not supported\n",from_name,to_name)); - - if (!unix_charset || !*unix_charset) unix_charset = "ASCII"; - if (!dos_charset || !*dos_charset) dos_charset = "ASCII"; + int c1, c2; + + /* so that charset_name() works we need to get the UNIX<->UCS2 going + first */ + if (!conv_handles[CH_UNIX][CH_UCS2]) { + conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open("UCS-2LE", "ASCII"); + } + if (!conv_handles[CH_UCS2][CH_UNIX]) { + conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); + } - ICONV(ucs2_to_unix, "UCS-2LE", unix_charset) - ICONV(unix_to_ucs2, unix_charset, "UCS-2LE") - ICONV(dos_to_unix, dos_charset, unix_charset) - ICONV(unix_to_dos, unix_charset, dos_charset) -#undef ICONV + for (c1=0;c1 Date: Mon, 24 Sep 2001 06:24:14 +0000 Subject: fixed a silly off by 1 bug (This used to be commit e558ab6ac8930e3393291fe12289ad43175b8a1d) --- source3/lib/charcnv.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ebcceef816..0e7d5241f4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -99,6 +99,9 @@ size_t convert_string(charset_t from, charset_t to, static int initialised; smb_iconv_t descriptor; + if (srclen == -1) srclen = strlen(src)+1; + if (destlen == -1) destlen = strlen(dest)+1; + if (!initialised) { initialised = 1; init_iconv(); -- cgit From 4fe127dbe88af47178a0dad46e42aa6400ade67e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Sep 2001 05:20:43 +0000 Subject: added a little smbtorture test for dumping the unicode table of a server. This is just a framework right now - I want this to eventually replace the win32 test code from monyo The interesting this about this test is that it shows up a really horrible performance bug in our stat cache code. I'll see if I can fix it. (This used to be commit eb668b54af4925194c07b217724657f406ec00d0) --- source3/lib/charcnv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0e7d5241f4..5afc638a8d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -100,7 +100,6 @@ size_t convert_string(charset_t from, charset_t to, smb_iconv_t descriptor; if (srclen == -1) srclen = strlen(src)+1; - if (destlen == -1) destlen = strlen(dest)+1; if (!initialised) { initialised = 1; -- 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/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5afc638a8d..adcd8b2aa9 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -94,7 +94,7 @@ size_t convert_string(charset_t from, charset_t to, { size_t i_len, o_len; size_t retval; - char* inbuf = (char*)src; + const char* inbuf = (const char*)src; char* outbuf = (char*)dest; static int initialised; smb_iconv_t descriptor; -- cgit From b7ca6ec034c8b707e462e4a4457a65ce9bea0f79 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Sep 2001 13:30:52 +0000 Subject: make strupper() and strlower() not modify the string if it doesn't need modifying that makes constant strings OK (This used to be commit 57196635d9b7edfcbfe1708dd22308ab30c02240) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index adcd8b2aa9..55d56acf59 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -140,7 +140,7 @@ int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; - strupper_w(buffer); + if (!strupper_w(buffer) && (dest == src)) return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } @@ -150,7 +150,7 @@ int unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); len=size/2; - strlower_w(buffer); + if (!strlower_w(buffer) && (dest == src)) return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/lib/charcnv.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 55d56acf59..45d7d4d8d5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,8 +22,6 @@ */ #include "includes.h" -extern int DEBUGLEVEL; - static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -- cgit From 9bcd133e9e7b0cfe974f273fb23409d660af8358 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 Oct 2001 12:18:20 +0000 Subject: switched over to a new method of handling uppercase/lowercase mappings for unicode strings. The new method relies on 3 files that are mmap'd at startup to provide the mapping tables. The upcase.dat and lowcase.dat tables should be the same on all systems. The valid.dat table says what characters are valid in 8.3 names, and differs between systems. I'm committing the japanese valid.dat here, in future we need some way of automatically installing and choosing a appropriate table. This commit also adds my mini tdb based gettext replacement in intl/lang_tdb.c. I have not enabled this yet and have not removed the old gettext code as the new code is still being looked at by Monyo. Right now the code assumes that the upcase.dat, lowcase.dat and valid.dat files are installed in the Samba lib directory. That is not a good choice, but I'll leave them there until we work out the new install directory structure for Samba 3.0. simo - please look at the isvalid_w() function and think about using it in your new mangling code. That should be the final step to correctly passing the chargen test code from monyo. (This used to be commit 1c221994f118dd542a158b2db51e07d04d0e9314) --- source3/lib/charcnv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 45d7d4d8d5..b7af6fef4b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -101,6 +101,7 @@ size_t convert_string(charset_t from, charset_t to, if (!initialised) { initialised = 1; + load_case_tables(); init_iconv(); } -- 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/charcnv.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b7af6fef4b..d14a1f04e4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -61,15 +61,15 @@ void init_iconv(void) for (c1=0;c1 Date: Mon, 29 Oct 2001 08:26:45 +0000 Subject: More spelling and grammer from Vance. Thanks! Andrew Bartlett (This used to be commit f019bed7663b4a20c1b5ab6b59fcadda17b89acd) --- source3/lib/charcnv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d14a1f04e4..e55de729c2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -77,10 +77,10 @@ void init_iconv(void) } /**************************************************************************** - Convert string from one encoding to another, makeing error checking etc + Convert string from one encoding to another, making error checking etc Parameters: descriptor - conversion descriptor, created in init_iconv - src - pointer to source string (multibute or singlebyte) + src - pointer to source string (multibyte or singlebyte) srclen - length of the source string in bytes dest - pointer to destination string (multibyte or singlebyte) destlen - maximal length allowed for string @@ -120,14 +120,14 @@ size_t convert_string(charset_t from, charset_t to, if(retval==-1) { char *reason="unknown error"; switch(errno) - { case EINVAL: reason="Incomplete multybyte sequence"; break; + { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; DEBUG(0, ("Required %d, available %d\n", srclen, destlen)); break; - case EILSEQ: reason="Illegal myltybyte sequence"; break; + case EILSEQ: reason="Illegal myltibyte sequence"; break; } - DEBUG(0,("Conversion error:%s(%s)\n",reason,inbuf)); + DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ } return destlen-o_len; @@ -336,7 +336,7 @@ int pull_ucs2_fstring(char *dest, const void *src) /**************************************************************************** copy a string from a char* src to a unicode or ascii -dos code page destination choosing unicode or ascii based on the +dos codepage destination choosing unicode or ascii based on the flags in the SMB buffer starting at base_ptr return the number of bytes occupied by the string in the destination flags can have: -- cgit From 740d6f5dd60bef72037ed5fcd7b2192af22c2e41 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Nov 2001 18:26:53 +0000 Subject: a big one: - old mangle code has gone, the new one based on tdb seem resonably ok probably the valid.dat table need to be updated to treat wild chars as invalid ones (work ok without it) - a LOT of new string manipulation function for unicode, they are somewhat tested but a review would not be bad - some new function I will need for the new unix_convert function I'm writing, this will be renamed filename_convert and use only unicode strings. - charconv, I attached a comment, if someone wnat to look if I'm right or just was hacking to late in the night to make a sane one :) of course any bug is my responsibility an will be pleased to see patches if you find any. :-) Simo. (This used to be commit ee19f7efb6ea9216fc91cf112ac1afa691983e9d) --- source3/lib/charcnv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index e55de729c2..ebf316d9dd 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -123,7 +123,13 @@ size_t convert_string(charset_t from, charset_t to, { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; DEBUG(0, ("Required %d, available %d\n", - srclen, destlen)); + srclen, destlen)); + /* we are not sure we need srclen bytes, + may be more, may be less. + We only know we need more than destlen + bytes ---simo */ + + break; case EILSEQ: reason="Illegal myltibyte sequence"; break; } -- cgit From 5a91b271f6076f5c2972dfa4fcc41b800bba77b7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 7 Nov 2001 18:14:46 +0000 Subject: add convert_string_allocate() function (This used to be commit 8b494b0be323c983b7ea3d1dcf1f61216396caec) --- source3/lib/charcnv.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ebf316d9dd..2929233388 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -26,6 +26,8 @@ static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; +static int initialized; + /**************************************************************************** return the name of a charset to give to iconv() ****************************************************************************/ @@ -92,15 +94,14 @@ size_t convert_string(charset_t from, charset_t to, { size_t i_len, o_len; size_t retval; - const char* inbuf = (const char*)src; + char* inbuf = (char*)src; char* outbuf = (char*)dest; - static int initialised; smb_iconv_t descriptor; if (srclen == -1) srclen = strlen(src)+1; - if (!initialised) { - initialised = 1; + if (!initialized) { + initialized = 1; load_case_tables(); init_iconv(); } @@ -118,7 +119,8 @@ size_t convert_string(charset_t from, charset_t to, o_len=destlen; retval=smb_iconv(descriptor,&inbuf, &i_len, &outbuf, &o_len); if(retval==-1) - { char *reason="unknown error"; + { + char *reason="unknown error"; switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; @@ -139,6 +141,85 @@ size_t convert_string(charset_t from, charset_t to, return destlen-o_len; } +/* you must provide source lenght -1 is not accepted as lenght. + this function will return the size in bytes of the converted string + or -1 in case of error. + */ +size_t convert_string_allocate(charset_t from, charset_t to, + void const *src, size_t srclen, void **dest) +{ + size_t i_len, o_len, destlen; + size_t retval; + char* inbuf = (char *)src; + char *outbuf, *ob; + smb_iconv_t descriptor; + + *dest = NULL; + + if (src == NULL || srclen == -1) return -1; + + if (!initialized) { + initialized = 1; + load_case_tables(); + init_iconv(); + } + + descriptor = conv_handles[from][to]; + + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { + /* conversion not supported, return -1*/ + return -1; + } + + destlen = MAX(srclen, 1024); + outbuf = NULL; +convert: + destlen = destlen * 2; + ob = (char *)realloc(outbuf, destlen); + if (!ob) { + DEBUG(0, ("convert_string_allocate: realloc failed!\n")); + free(outbuf); + return -1; + } + else outbuf = ob; + i_len = srclen; + o_len = destlen; + retval = smb_iconv(descriptor, + &inbuf, &i_len, + &outbuf, &o_len); + if(retval == -1) + { + char *reason="unknown error"; + switch(errno) + { + case EINVAL: + reason="Incomplete multibyte sequence"; + break; + case E2BIG: + goto convert; + break; + case EILSEQ: + reason="Illegal myltibyte sequence"; + break; + } + DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); + /* smb_panic(reason); */ + return -1; + } + + destlen = destlen - o_len; + *dest = (char *)malloc(destlen); + if (!*dest) { + DEBUG(0, ("convert_string_allocate: out of memory!\n")); + free(outbuf); + return -1; + } + memcpy(*dest, outbuf, destlen); + free(outbuf); + + return destlen; +} + int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { int size; -- cgit From 5d152d24a39386a7b595f9fc157d86dff38c39dc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 10 Nov 2001 15:21:54 +0000 Subject: fixed, moved and added some functions note the useful acnv_uxu2 and acnv_u2ux functions in charcnv.c (This used to be commit 64dde3b64fc091cda95fc4ed145595b5d79b2e01) --- source3/lib/charcnv.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2929233388..59a2af72a4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -171,7 +171,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, return -1; } - destlen = MAX(srclen, 1024); + destlen = MAX(srclen, 512); outbuf = NULL; convert: destlen = destlen * 2; @@ -208,15 +208,13 @@ convert: } destlen = destlen - o_len; - *dest = (char *)malloc(destlen); + *dest = (char *)realloc(outbuf,destlen); if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); free(outbuf); return -1; } - memcpy(*dest, outbuf, destlen); - free(outbuf); - + return destlen; } @@ -478,3 +476,41 @@ int align_string(const void *base_ptr, const char *p, int flags) } return 0; } + + + +/**************************************************************************** +convert from ucs2 to unix charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +char *acnv_u2ux(const smb_ucs2_t *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen_w(src) + 1; + dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} + +/**************************************************************************** +convert from ucs2 to unix charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +smb_ucs2_t *acnv_uxu2(const char *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen(src) + 1; + dlen = convert_string_allocate(CH_UNIX, CH_UCS2, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} -- cgit From 84244244710790f2058ee90b2dc80e9c252841dd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 Nov 2001 00:53:34 +0000 Subject: some bugfix and new functions, modified mangle.c to use mosltly acnv_????() functions. this should make also build farm happy (This used to be commit 8bb5cb27c2012b8967482255d48a1b48d3acd9db) --- source3/lib/charcnv.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 59a2af72a4..5ed31d2a4c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -4,6 +4,7 @@ Character set conversion Extensions Copyright (C) Igor Vergeichik 2001 Copyright (C) Andrew Tridgell 2001 + Copyright (C) Simo Sorce 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 @@ -150,7 +151,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, { size_t i_len, o_len, destlen; size_t retval; - char* inbuf = (char *)src; + char *inbuf = (char *)src; char *outbuf, *ob; smb_iconv_t descriptor; @@ -178,7 +179,7 @@ convert: ob = (char *)realloc(outbuf, destlen); if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - free(outbuf); + SAFE_FREE(outbuf); return -1; } else outbuf = ob; @@ -208,10 +209,11 @@ convert: } destlen = destlen - o_len; + *dest = (char *)realloc(ob,destlen); *dest = (char *)realloc(outbuf,destlen); if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); - free(outbuf); + SAFE_FREE(ob); return -1; } @@ -491,14 +493,14 @@ char *acnv_u2ux(const smb_ucs2_t *src) size_t dlen; void *dest; - slen = strlen_w(src) + 1; + slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); if (dlen == -1) return NULL; else return dest; } /**************************************************************************** -convert from ucs2 to unix charset and return the +convert from unix to ucs2 charset and return the allocated and converted string or NULL if an error occurred. you must provide a zero terminated string. the returning string will be zero terminated. @@ -514,3 +516,39 @@ smb_ucs2_t *acnv_uxu2(const char *src) if (dlen == -1) return NULL; else return dest; } + +/**************************************************************************** +convert from ucs2 to dos charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +char *acnv_u2dos(const smb_ucs2_t *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); + dlen = convert_string_allocate(CH_UCS2, CH_DOS, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} + +/**************************************************************************** +convert from dos to ucs2 charset and return the +allocated and converted string or NULL if an error occurred. +you must provide a zero terminated string. +the returning string will be zero terminated. +****************************************************************************/ +smb_ucs2_t *acnv_dosu2(const char *src) +{ + size_t slen; + size_t dlen; + void *dest; + + slen = strlen(src) + 1; + dlen = convert_string_allocate(CH_DOS, CH_UCS2, src, slen, &dest); + if (dlen == -1) return NULL; + else return dest; +} -- cgit From 25f51f49b13f46907b19761720de380513b3eec9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 Nov 2001 01:31:43 +0000 Subject: messed up with patches, this should be the right one, sorry (This used to be commit 023514a0b6170b1907696a2147ee44dc3aa4589d) --- source3/lib/charcnv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5ed31d2a4c..27e00a589e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -209,8 +209,7 @@ convert: } destlen = destlen - o_len; - *dest = (char *)realloc(ob,destlen); - *dest = (char *)realloc(outbuf,destlen); + *dest = (char *)Realloc(ob,destlen); if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); SAFE_FREE(ob); -- cgit From 1a74f88b1fa792d215ce0a284aa96214e8995d66 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 23 Nov 2001 04:24:26 +0000 Subject: Quieten gcc const warning. doxyfy. (This used to be commit 6ddd8e7bf69d8aee4148cbcf72de55c903d5f0a1) --- source3/lib/charcnv.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 27e00a589e..11ae2d9143 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -79,16 +79,16 @@ void init_iconv(void) } } -/**************************************************************************** - Convert string from one encoding to another, making error checking etc - Parameters: - descriptor - conversion descriptor, created in init_iconv - src - pointer to source string (multibyte or singlebyte) - srclen - length of the source string in bytes - dest - pointer to destination string (multibyte or singlebyte) - destlen - maximal length allowed for string -return the number of bytes occupied in the destination -****************************************************************************/ +/** + * Convert string from one encoding to another, making error checking etc + * + * @param descriptor conversion descriptor, created in init_iconv() + * @param src pointer to source string (multibyte or singlebyte) + * @param srclen length of the source string in bytes + * @param dest pointer to destination string (multibyte or singlebyte) + * @param destlen maximal length allowed for string + * @retval the number of bytes occupied in the destination + **/ size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) @@ -118,7 +118,7 @@ size_t convert_string(charset_t from, charset_t to, i_len=srclen; o_len=destlen; - retval=smb_iconv(descriptor,&inbuf, &i_len, &outbuf, &o_len); + retval = smb_iconv(descriptor, &(const char *)inbuf, &i_len, &outbuf, &o_len); if(retval==-1) { char *reason="unknown error"; @@ -142,10 +142,14 @@ size_t convert_string(charset_t from, charset_t to, return destlen-o_len; } -/* you must provide source lenght -1 is not accepted as lenght. - this function will return the size in bytes of the converted string - or -1 in case of error. - */ +/** + * Convert between character sets, allocating a new buffer for the result. + * + * @param srclen length of source buffer. + * @note -1 is not accepted for srclen. + * + * @retval Size in bytes of the converted string; or -1 in case of error. + **/ size_t convert_string_allocate(charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { @@ -186,8 +190,8 @@ convert: i_len = srclen; o_len = destlen; retval = smb_iconv(descriptor, - &inbuf, &i_len, - &outbuf, &o_len); + &(const char *) inbuf, &i_len, + &outbuf, &o_len); if(retval == -1) { char *reason="unknown error"; -- cgit From 24d03aefe9c3055c979b6f5b178dd0e3df1225cc Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 23 Nov 2001 04:53:56 +0000 Subject: More better now. (This used to be commit a875b3a6e7a9501a31fe15fb9b04394a95484e77) --- source3/lib/charcnv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 11ae2d9143..ab9554f848 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -95,7 +95,7 @@ size_t convert_string(charset_t from, charset_t to, { size_t i_len, o_len; size_t retval; - char* inbuf = (char*)src; + const char* inbuf = (char*)src; char* outbuf = (char*)dest; smb_iconv_t descriptor; @@ -118,7 +118,7 @@ size_t convert_string(charset_t from, charset_t to, i_len=srclen; o_len=destlen; - retval = smb_iconv(descriptor, &(const char *)inbuf, &i_len, &outbuf, &o_len); + retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); if(retval==-1) { char *reason="unknown error"; @@ -155,7 +155,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, { size_t i_len, o_len, destlen; size_t retval; - char *inbuf = (char *)src; + const char *inbuf = (char *)src; char *outbuf, *ob; smb_iconv_t descriptor; @@ -190,7 +190,7 @@ convert: i_len = srclen; o_len = destlen; retval = smb_iconv(descriptor, - &(const char *) inbuf, &i_len, + &inbuf, &i_len, &outbuf, &o_len); if(retval == -1) { -- cgit From f6b962fba37a1ac105301d699708e541ce34d3b4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Nov 2001 23:54:07 +0000 Subject: fixed some krb5 ifdefs (This used to be commit 23ef22f11700bbaa5778a9678a990a2b041fcefe) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ab9554f848..2e5413c5c0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -95,7 +95,7 @@ size_t convert_string(charset_t from, charset_t to, { size_t i_len, o_len; size_t retval; - const char* inbuf = (char*)src; + const char* inbuf = (const char*)src; char* outbuf = (char*)dest; smb_iconv_t descriptor; @@ -155,7 +155,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, { size_t i_len, o_len, destlen; size_t retval; - const char *inbuf = (char *)src; + const char *inbuf = (const char *)src; char *outbuf, *ob; smb_iconv_t descriptor; -- 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/charcnv.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2e5413c5c0..256bd7e88c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -51,6 +51,7 @@ static char *charset_name(charset_t ch) void init_iconv(void) { int c1, c2; + BOOL did_reload = False; /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ @@ -66,6 +67,12 @@ void init_iconv(void) for (c2=0;c2from_name) == 0 && + strcmp(n2, conv_handles[c1][c2]->to_name) == 0) continue; + + did_reload = True; + if (conv_handles[c1][c2]) { smb_iconv_close(conv_handles[c1][c2]); } @@ -77,6 +84,10 @@ void init_iconv(void) } } } + + if (did_reload) { + init_valid_table(); + } } /** @@ -105,6 +116,7 @@ size_t convert_string(charset_t from, charset_t to, initialized = 1; load_case_tables(); init_iconv(); + init_valid_table(); } descriptor = conv_handles[from][to]; @@ -136,7 +148,6 @@ size_t convert_string(charset_t from, charset_t to, break; case EILSEQ: reason="Illegal myltibyte sequence"; break; } - DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ } return destlen-o_len; -- cgit From 84ecd95dba6cf03070432b3cc37d511d310d1325 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Dec 2001 14:05:22 +0000 Subject: more irix -64 portability fixes (This used to be commit 65e857b36e170e3ecd78bf6695ae73342e9c04cd) --- source3/lib/charcnv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 256bd7e88c..481effbad5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -213,7 +213,6 @@ convert: break; case E2BIG: goto convert; - break; case EILSEQ: reason="Illegal myltibyte sequence"; break; -- cgit From c4fe824c42a36f19d19eb5cca5f62f883410ab98 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 22 Jan 2002 03:51:28 +0000 Subject: We have to do some initialization before the string conversion routines can work. The code was copied into both convert_string and convert_string_allocate -- I split it into a little static function, and removed an apparently duplicate call to init_valid_table(). (This used to be commit 7f7d22880d40c7344bc402203dd150255fc694cf) --- source3/lib/charcnv.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 481effbad5..48b9cad731 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -27,8 +27,6 @@ static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -static int initialized; - /**************************************************************************** return the name of a charset to give to iconv() ****************************************************************************/ @@ -45,6 +43,19 @@ static char *charset_name(charset_t ch) return ret; } + +static void lazy_initialize_conv(void) +{ + static int initialized = False; + + if (!initialized) { + initialized = True; + load_case_tables(); + init_iconv(); + init_valid_table(); + } +} + /**************************************************************************** Initialize iconv conversion descriptors ****************************************************************************/ @@ -112,12 +123,7 @@ size_t convert_string(charset_t from, charset_t to, if (srclen == -1) srclen = strlen(src)+1; - if (!initialized) { - initialized = 1; - load_case_tables(); - init_iconv(); - init_valid_table(); - } + lazy_initialize_conv(); descriptor = conv_handles[from][to]; @@ -174,11 +180,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, if (src == NULL || srclen == -1) return -1; - if (!initialized) { - initialized = 1; - load_case_tables(); - init_iconv(); - } + lazy_initialize_conv(); descriptor = conv_handles[from][to]; -- 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/charcnv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 48b9cad731..a1cda7bff3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. Character set conversion Extensions Copyright (C) Igor Vergeichik 2001 Copyright (C) Andrew Tridgell 2001 -- cgit From 407cd42143f35ea62ac9205a85263d494e494d25 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 4 Feb 2002 00:59:23 +0000 Subject: better debug messages! (This used to be commit e3bb6867454307ae592115e205d32ddd53988678) --- source3/lib/charcnv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a1cda7bff3..d19911dfe2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -185,6 +185,7 @@ size_t convert_string_allocate(charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, return -1*/ + DEBUG(3, ("convert_string_allocate: conversion not supported!\n")); return -1; } -- cgit From efa1571b8bdc178a981dc37a2c4d1add67b9c0bd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 19 Feb 2002 23:02:39 +0000 Subject: Patch from Hasch@t-online.de (Juergen Hasch) to add UTF-8 as an explict character set for conversion. To be used in Winbind and the 'net ads' commands. Andrew Bartlett (This used to be commit fa9d3060ff7510e176d7608b49075379500f55c4) --- source3/lib/charcnv.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d19911dfe2..97551ede1c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -37,6 +37,7 @@ static char *charset_name(charset_t ch) else if (ch == CH_UNIX) ret = lp_unix_charset(); else if (ch == CH_DOS) ret = lp_dos_charset(); else if (ch == CH_DISPLAY) ret = lp_display_charset(); + else if (ch == CH_UTF8) ret = "UTF-8"; if (!ret || !*ret) ret = "ASCII"; return ret; @@ -151,7 +152,7 @@ size_t convert_string(charset_t from, charset_t to, break; - case EILSEQ: reason="Illegal myltibyte sequence"; break; + case EILSEQ: reason="Illegal multibyte sequence"; break; } /* smb_panic(reason); */ } @@ -390,6 +391,37 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i return len; } +/**************************************************************************** +copy a string from a char* src to a UTF-8 destination +return the number of bytes occupied by the string in the destination +flags can have: + STR_TERMINATE means include the null termination + STR_UPPER means uppercase in the destination +dest_len is the maximum length allowed in the destination. If dest_len +is -1 then no maxiumum is used +****************************************************************************/ +int push_utf8(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) +{ + int src_len = strlen(src); + pstring tmpbuf; + + /* treat a pstring as "unlimited" length */ + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (flags & STR_UPPER) { + pstrcpy(tmpbuf, src); + strupper(tmpbuf); + src = tmpbuf; + } + + if (flags & STR_TERMINATE) { + src_len++; + } + + return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len); +} /**************************************************************************** copy a string from a ucs2 source to a unix char* destination @@ -435,6 +467,40 @@ int pull_ucs2_fstring(char *dest, const void *src) return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); } +/**************************************************************************** +copy a string from a utf-8 source to a unix char* destination +flags can have: + STR_TERMINATE means the string in src is null terminated +if STR_TERMINATE is set then src_len is ignored +src_len is the length of the source area in bytes +return the number of bytes occupied by the string in src +the resulting string in "dest" is always null terminated +****************************************************************************/ +int pull_utf8(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, int flags) +{ + int ret; + + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (flags & STR_TERMINATE) src_len = strlen(src)+1; + + ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); + if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + + return src_len; +} + +int pull_utf8_pstring(char *dest, const void *src) +{ + return pull_utf8(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); +} + +int pull_utf8_fstring(char *dest, const void *src) +{ + return pull_utf8(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); +} /**************************************************************************** copy a string from a char* src to a unicode or ascii -- cgit From 121d3238d72adc20bc08418d30eca1d41b4ff749 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 1 Mar 2002 00:57:47 +0000 Subject: This should kill off the 'cannot convert' error messages on non-iconv hosts. (This used to be commit 2a30960276ae65b60d01caf9464808d75a812e40) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 97551ede1c..df98c5a20b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -37,7 +37,7 @@ static char *charset_name(charset_t ch) else if (ch == CH_UNIX) ret = lp_unix_charset(); else if (ch == CH_DOS) ret = lp_dos_charset(); else if (ch == CH_DISPLAY) ret = lp_display_charset(); - else if (ch == CH_UTF8) ret = "UTF-8"; + else if (ch == CH_UTF8) ret = "UTF8"; if (!ret || !*ret) ret = "ASCII"; return ret; -- cgit From e4235f6b8403197077ab5ad536e080d09bb980ff Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 1 Mar 2002 01:11:02 +0000 Subject: Fix up the pull_utf8_fstring/pstring functions, and add their push eqivilants. patch by Hasch@t-online.de (Juergen Hasch) Andrew Bartlett (This used to be commit ba2570f518e07c95b952fb824a2d0b040b912bcc) --- source3/lib/charcnv.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index df98c5a20b..d64033b498 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -400,7 +400,7 @@ flags can have: dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used ****************************************************************************/ -int push_utf8(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) +int push_utf8(void *dest, const char *src, int dest_len, int flags) { int src_len = strlen(src); pstring tmpbuf; @@ -423,6 +423,16 @@ int push_utf8(const void *base_ptr, void *dest, const char *src, int dest_len, i return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len); } +int push_utf8_fstring(void *dest, const char *src) +{ + return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE); +} + +int push_utf8_pstring(void *dest, const char *src) +{ + return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE); +} + /**************************************************************************** copy a string from a ucs2 source to a unix char* destination flags can have: @@ -476,7 +486,7 @@ src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated ****************************************************************************/ -int pull_utf8(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, int flags) +int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) { int ret; @@ -494,12 +504,12 @@ int pull_utf8(const void *base_ptr, char *dest, const void *src, int dest_len, i int pull_utf8_pstring(char *dest, const void *src) { - return pull_utf8(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); + return pull_utf8(dest, src, sizeof(pstring), -1, STR_TERMINATE); } int pull_utf8_fstring(char *dest, const void *src) { - return pull_utf8(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); + return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE); } /**************************************************************************** -- cgit From fbdf45721b65985eb0e2f8d8f7497bce436e0a9f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 23 Mar 2002 08:39:04 +0000 Subject: Patch from Hasch@t-online.de (Juergen Hasch) to add allocate and talloc push/pull utf8 functions. To be used for international ADS support. Andrew Bartlett (This used to be commit 9ab144810efeb0b086257143b01ca47ee5718861) --- source3/lib/charcnv.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d64033b498..d4e46ec89a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -163,6 +163,7 @@ size_t convert_string(charset_t from, charset_t to, * Convert between character sets, allocating a new buffer for the result. * * @param srclen length of source buffer. + * @param dest always set at least to NULL * @note -1 is not accepted for srclen. * * @retval Size in bytes of the converted string; or -1 in case of error. @@ -217,7 +218,7 @@ convert: case E2BIG: goto convert; case EILSEQ: - reason="Illegal myltibyte sequence"; + reason="Illegal multibyte sequence"; break; } DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); @@ -236,6 +237,32 @@ convert: return destlen; } +/** + * Convert between character sets, allocating a new buffer using talloc for the result. + * + * @param srclen length of source buffer. + * @param dest always set at least to NULL + * @note -1 is not accepted for srclen. + * + * @retval Size in bytes of the converted string; or -1 in case of error. + **/ +size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void **dest) +{ + void *ob; + size_t dest_len; + + *dest = NULL; + dest_len=convert_string_allocate(from, to, src, srclen, (void **)&ob); + if (dest_len == -1) + return -1; + *dest = talloc_strdup(ctx, (char *)ob); + SAFE_FREE(ob); + if (*dest == NULL) + return -1; + return dest_len; +} + int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { int size; @@ -433,6 +460,36 @@ int push_utf8_pstring(void *dest, const char *src) return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE); } +/** + * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int push_utf8_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + int src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, dest); +} + +/** + * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int push_utf8_allocate(void **dest, const char *src) +{ + int src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, dest); +} + /**************************************************************************** copy a string from a ucs2 source to a unix char* destination flags can have: @@ -512,6 +569,34 @@ int pull_utf8_fstring(char *dest, const void *src) return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE); } +/** + * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int pull_utf8_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + int src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, dest); +} + +/** + * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int pull_utf8_allocate(void **dest, const char *src) +{ + int src_len = strlen(src)+1; + *dest = NULL; + return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest); +} + /**************************************************************************** copy a string from a char* src to a unicode or ascii dos codepage destination choosing unicode or ascii based on the -- cgit From 62098eade38fe0a948e05527b80d54b4b0df1d24 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 25 Mar 2002 07:41:42 +0000 Subject: add {push,pull}_ucs2{allocate,talloc}() functions. Andrew Bartlett (This used to be commit ce7990b4a4f251536dd26be5a62c12711df57787) --- source3/lib/charcnv.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d4e46ec89a..cdfca8eb97 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -418,6 +418,36 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i return len; } +/** + * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + int src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, dest); +} + +/** + * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int push_ucs2_allocate(void **dest, const char *src) +{ + int src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, dest); +} + /**************************************************************************** copy a string from a char* src to a UTF-8 destination return the number of bytes occupied by the string in the destination @@ -534,6 +564,34 @@ int pull_ucs2_fstring(char *dest, const void *src) return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); } +/** + * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int pull_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + int src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, dest); +} + +/** + * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer + * + * @param dest always set at least to NULL + * + * @retval The number of bytes occupied by the string in the destination + **/ +int pull_ucs2_allocate(void **dest, const char *src) +{ + int src_len = strlen(src)+1; + *dest = NULL; + return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); +} + /**************************************************************************** copy a string from a utf-8 source to a unix char* destination flags can have: -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/lib/charcnv.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cdfca8eb97..d42dc994b0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -143,7 +143,7 @@ size_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; - DEBUG(0, ("Required %d, available %d\n", + DEBUG(0, ("convert_string: Required %d, available %d\n", srclen, destlen)); /* we are not sure we need srclen bytes, may be more, may be less. @@ -354,7 +354,15 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src) + 1; + } else { + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; + } + } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -525,7 +533,7 @@ copy a string from a ucs2 source to a unix char* destination flags can have: STR_TERMINATE means the string in src is null terminated STR_NOALIGN means don't try to align -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored if it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated @@ -543,7 +551,15 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen_w(src)*2 + 2; + } else { + int len = strnlen_w(src, src_len/2); + if (len < src_len/2) len++; + src_len = len*2; + } + } /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +625,15 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src) + 1; + } else { + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; + } + } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -687,7 +711,7 @@ flags can have: STR_UNICODE means to force as unicode STR_ASCII use ascii even with unicode packet STR_NOALIGN means don't do alignment -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored is it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated -- cgit From b2edf254eda92f775e7d3d9b6793b4d77f9000b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 17:00:51 +0000 Subject: sync 3.0 branch with head (This used to be commit 3928578b52cfc949be5e0ef444fce1558d75f290) --- source3/lib/charcnv.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d42dc994b0..6e96136643 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -249,15 +249,15 @@ convert: size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { - void *ob; + void *alloced_string; size_t dest_len; *dest = NULL; - dest_len=convert_string_allocate(from, to, src, srclen, (void **)&ob); + dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string); if (dest_len == -1) return -1; - *dest = talloc_strdup(ctx, (char *)ob); - SAFE_FREE(ob); + *dest = talloc_memdup(ctx, alloced_string, dest_len); + SAFE_FREE(alloced_string); if (*dest == NULL) return -1; return dest_len; @@ -505,12 +505,12 @@ int push_utf8_pstring(void *dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int push_utf8_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +int push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { int src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest); } /** @@ -562,7 +562,8 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i } /* ucs2 is always a multiple of 2 bytes */ - src_len &= ~1; + if (src_len != -1) + src_len &= ~1; ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -658,11 +659,11 @@ int pull_utf8_fstring(char *dest, const void *src) * * @retval The number of bytes occupied by the string in the destination **/ -int pull_utf8_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +int pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { int src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, dest); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); } /** -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/charcnv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6e96136643..cd8aa4fe55 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -432,13 +432,14 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i * @param dest always set at least to NULL * * @retval The number of bytes occupied by the string in the destination + * or -1 in case of error. **/ -int push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +int push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { int src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } /** @@ -447,13 +448,14 @@ int push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) * @param dest always set at least to NULL * * @retval The number of bytes occupied by the string in the destination + * or -1 in case of error. **/ -int push_ucs2_allocate(void **dest, const char *src) +int push_ucs2_allocate(smb_ucs2_t **dest, const char *src) { int src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, dest); + return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } /**************************************************************************** -- cgit From f2d1f19a66ebaf9b88d23c0faa2412536cc74cda Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 1 Oct 2002 18:26:00 +0000 Subject: syncing up with HEAD. Seems to be a lot of differences creeping in (i ignored the new SAMBA stuff, but the rest of this looks like it should have been merged already). (This used to be commit 3de09e5cf1f667e410ee8b9516a956860ce7290f) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cd8aa4fe55..d0cef52c92 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -522,12 +522,12 @@ int push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int push_utf8_allocate(void **dest, const char *src) +int push_utf8_allocate(char **dest, const char *src) { int src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, dest); + return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } /**************************************************************************** -- cgit From da45fbf63574b774504486e32e87811379e72d26 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 Nov 2002 22:13:05 +0000 Subject: Fix all returns to be size_t (they are all unsigned). Fixup strlen being done on ucs2 strings. Jeremy. (This used to be commit 9a6c6946193289eac5b91fe6fd236c0742ec6f8c) --- source3/lib/charcnv.c | 457 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 213 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d0cef52c92..04145fd17a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -27,8 +27,9 @@ static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /**************************************************************************** -return the name of a charset to give to iconv() + Return the name of a charset to give to iconv(). ****************************************************************************/ + static char *charset_name(charset_t ch) { char *ret = NULL; @@ -43,7 +44,6 @@ static char *charset_name(charset_t ch) return ret; } - static void lazy_initialize_conv(void) { static int initialized = False; @@ -57,8 +57,9 @@ static void lazy_initialize_conv(void) } /**************************************************************************** - Initialize iconv conversion descriptors + Initialize iconv conversion descriptors. ****************************************************************************/ + void init_iconv(void) { int c1, c2; @@ -66,13 +67,11 @@ void init_iconv(void) /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ - if (!conv_handles[CH_UNIX][CH_UCS2]) { + if (!conv_handles[CH_UNIX][CH_UCS2]) conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open("UCS-2LE", "ASCII"); - } - if (!conv_handles[CH_UCS2][CH_UNIX]) { + + if (!conv_handles[CH_UCS2][CH_UNIX]) conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); - } - for (c1=0;c1from_name) == 0 && - strcmp(n2, conv_handles[c1][c2]->to_name) == 0) continue; + strcmp(n2, conv_handles[c1][c2]->to_name) == 0) + continue; did_reload = True; - if (conv_handles[c1][c2]) { + if (conv_handles[c1][c2]) smb_iconv_close(conv_handles[c1][c2]); - } + conv_handles[c1][c2] = smb_iconv_open(n2,n1); if (conv_handles[c1][c2] == (smb_iconv_t)-1) { DEBUG(0,("Conversion from %s to %s not supported\n", @@ -111,6 +111,7 @@ void init_iconv(void) * @param destlen maximal length allowed for string * @retval the number of bytes occupied in the destination **/ + size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) @@ -121,7 +122,8 @@ size_t convert_string(charset_t from, charset_t to, char* outbuf = (char*)dest; smb_iconv_t descriptor; - if (srclen == -1) srclen = strlen(src)+1; + if (srclen == (size_t)-1) + srclen = strlen(src)+1; lazy_initialize_conv(); @@ -129,7 +131,7 @@ size_t convert_string(charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, use as is */ - int len = MIN(srclen,destlen); + size_t len = MIN(srclen,destlen); memcpy(dest,src,len); return len; } @@ -137,22 +139,24 @@ size_t convert_string(charset_t from, charset_t to, i_len=srclen; o_len=destlen; retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); - if(retval==-1) - { + if(retval==-1) { char *reason="unknown error"; - switch(errno) - { case EINVAL: reason="Incomplete multibyte sequence"; break; - case E2BIG: reason="No more room"; - DEBUG(0, ("convert_string: Required %d, available %d\n", - srclen, destlen)); - /* we are not sure we need srclen bytes, + switch(errno) { + case EINVAL: + reason="Incomplete multibyte sequence"; + break; + case E2BIG: + reason="No more room"; + DEBUG(0, ("convert_string: Required %d, available %d\n", + srclen, destlen)); + /* we are not sure we need srclen bytes, may be more, may be less. We only know we need more than destlen bytes ---simo */ - - break; - case EILSEQ: reason="Illegal multibyte sequence"; break; + case EILSEQ: + reason="Illegal multibyte sequence"; + break; } /* smb_panic(reason); */ } @@ -168,6 +172,7 @@ size_t convert_string(charset_t from, charset_t to, * * @retval Size in bytes of the converted string; or -1 in case of error. **/ + size_t convert_string_allocate(charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { @@ -179,7 +184,8 @@ size_t convert_string_allocate(charset_t from, charset_t to, *dest = NULL; - if (src == NULL || srclen == -1) return -1; + if (src == NULL || srclen == (size_t)-1) + return (size_t)-1; lazy_initialize_conv(); @@ -199,31 +205,30 @@ convert: if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); SAFE_FREE(outbuf); - return -1; + return (size_t)-1; } - else outbuf = ob; + else + outbuf = ob; i_len = srclen; o_len = destlen; retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); - if(retval == -1) - { + if(retval == -1) { char *reason="unknown error"; - switch(errno) - { - case EINVAL: - reason="Incomplete multibyte sequence"; - break; - case E2BIG: - goto convert; - case EILSEQ: - reason="Illegal multibyte sequence"; - break; + switch(errno) { + case EINVAL: + reason="Incomplete multibyte sequence"; + break; + case E2BIG: + goto convert; + case EILSEQ: + reason="Illegal multibyte sequence"; + break; } DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ - return -1; + return (size_t)-1; } destlen = destlen - o_len; @@ -231,7 +236,7 @@ convert: if (!*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); SAFE_FREE(ob); - return -1; + return (size_t)-1; } return destlen; @@ -246,6 +251,7 @@ convert: * * @retval Size in bytes of the converted string; or -1 in case of error. **/ + size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { @@ -254,37 +260,40 @@ size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, *dest = NULL; dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string); - if (dest_len == -1) - return -1; + if (dest_len == (size_t)-1) + return (size_t)-1; *dest = talloc_memdup(ctx, alloced_string, dest_len); SAFE_FREE(alloced_string); if (*dest == NULL) - return -1; + return (size_t)-1; return dest_len; } -int unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) +size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { - int size; + size_t size; smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strupper_w(buffer) && (dest == src)) return srclen; + if (!strupper_w(buffer) && (dest == src)) + return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } -int unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) +size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { - int size; + size_t size; smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strlower_w(buffer) && (dest == src)) return srclen; + if (!strlower_w(buffer) && (dest == src)) + return srclen; return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); } -int ucs2_align(const void *base_ptr, const void *p, int flags) +size_t ucs2_align(const void *base_ptr, const void *p, int flags) { - if (flags & (STR_NOALIGN|STR_ASCII)) return 0; + if (flags & (STR_NOALIGN|STR_ASCII)) + return 0; return PTR_DIFF(p, base_ptr) & 1; } @@ -295,18 +304,18 @@ return the number of bytes occupied by the string in the destination flags can have: STR_TERMINATE means include the null termination STR_UPPER means uppercase in the destination -dest_len is the maximum length allowed in the destination. If dest_len +dest_len is the maximum length in bytes allowed in the destination. If dest_len is -1 then no maxiumum is used ****************************************************************************/ -int push_ascii(void *dest, const char *src, int dest_len, int flags) + +size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { - int src_len = strlen(src); + size_t src_len = strlen(src); pstring tmpbuf; /* treat a pstring as "unlimited" length */ - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); @@ -314,93 +323,93 @@ int push_ascii(void *dest, const char *src, int dest_len, int flags) src = tmpbuf; } - if (flags & STR_TERMINATE) { + if (flags & STR_TERMINATE) src_len++; - } return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); } -int push_ascii_fstring(void *dest, const char *src) +size_t push_ascii_fstring(void *dest, const char *src) { return push_ascii(dest, src, sizeof(fstring), STR_TERMINATE); } -int push_ascii_pstring(void *dest, const char *src) +size_t push_ascii_pstring(void *dest, const char *src) { return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } -int push_pstring(void *dest, const char *src) +size_t push_pstring(void *dest, const char *src) { return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } - /**************************************************************************** -copy a string from a dos codepage source to a unix char* destination -flags can have: - STR_TERMINATE means the string in src is null terminated -if STR_TERMINATE is set then src_len is ignored -src_len is the length of the source area in bytes -return the number of bytes occupied by the string in src -the resulting string in "dest" is always null terminated + Copy a string from a dos codepage source to a unix char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + if STR_TERMINATE is set then src_len is ignored. + src_len is the length of the source area in bytes. + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. ****************************************************************************/ -int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags) + +size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { - int ret; + size_t ret; - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (flags & STR_TERMINATE) { - if (src_len == -1) { + if (src_len == (size_t)-1) { src_len = strlen(src) + 1; } else { - int len = strnlen(src, src_len); - if (len < src_len) len++; + size_t len = strnlen(src, src_len); + if (len < src_len) + len++; src_len = len; } } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; return src_len; } -int pull_ascii_pstring(char *dest, const void *src) +size_t pull_ascii_pstring(char *dest, const void *src) { return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE); } -int pull_ascii_fstring(char *dest, const void *src) +size_t pull_ascii_fstring(char *dest, const void *src) { return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } /**************************************************************************** -copy a string from a char* src to a unicode destination -return the number of bytes occupied by the string in the destination -flags can have: - STR_TERMINATE means include the null termination - STR_UPPER means uppercase in the destination - STR_NOALIGN means don't do alignment -dest_len is the maximum length allowed in the destination. If dest_len -is -1 then no maxiumum is used + Copy a string from a char* src to a unicode destination. + Return the number of bytes occupied by the string in the destination. + Flags can have: + STR_TERMINATE means include the null termination. + STR_UPPER means uppercase in the destination. + STR_NOALIGN means don't do alignment. + dest_len is the maximum length allowed in the destination. If dest_len + is -1 then no maxiumum is used. ****************************************************************************/ -int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) + +size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { - int len=0; - int src_len = strlen(src); + size_t len=0; + size_t src_len = strlen(src); pstring tmpbuf; /* treat a pstring as "unlimited" length */ - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); @@ -408,9 +417,8 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i src = tmpbuf; } - if (flags & STR_TERMINATE) { + if (flags & STR_TERMINATE) src_len++; - } if (ucs2_align(base_ptr, dest, flags)) { *(char *)dest = 0; @@ -434,9 +442,10 @@ int push_ucs2(const void *base_ptr, void *dest, const char *src, int dest_len, i * @retval The number of bytes occupied by the string in the destination * or -1 in case of error. **/ -int push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) + +size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); @@ -450,32 +459,33 @@ int push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) * @retval The number of bytes occupied by the string in the destination * or -1 in case of error. **/ -int push_ucs2_allocate(smb_ucs2_t **dest, const char *src) + +size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } /**************************************************************************** -copy a string from a char* src to a UTF-8 destination -return the number of bytes occupied by the string in the destination -flags can have: + Copy a string from a char* src to a UTF-8 destination. + Return the number of bytes occupied by the string in the destination + Flags can have: STR_TERMINATE means include the null termination STR_UPPER means uppercase in the destination -dest_len is the maximum length allowed in the destination. If dest_len -is -1 then no maxiumum is used + dest_len is the maximum length allowed in the destination. If dest_len + is -1 then no maxiumum is used. ****************************************************************************/ -int push_utf8(void *dest, const char *src, int dest_len, int flags) + +size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) { - int src_len = strlen(src); + size_t src_len = strlen(src); pstring tmpbuf; /* treat a pstring as "unlimited" length */ - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); @@ -483,19 +493,18 @@ int push_utf8(void *dest, const char *src, int dest_len, int flags) src = tmpbuf; } - if (flags & STR_TERMINATE) { + if (flags & STR_TERMINATE) src_len++; - } return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len); } -int push_utf8_fstring(void *dest, const char *src) +size_t push_utf8_fstring(void *dest, const char *src) { return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE); } -int push_utf8_pstring(void *dest, const char *src) +size_t push_utf8_pstring(void *dest, const char *src) { return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE); } @@ -507,9 +516,10 @@ int push_utf8_pstring(void *dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) + +size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest); @@ -522,63 +532,67 @@ int push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int push_utf8_allocate(char **dest, const char *src) + +size_t push_utf8_allocate(char **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } /**************************************************************************** -copy a string from a ucs2 source to a unix char* destination -flags can have: - STR_TERMINATE means the string in src is null terminated - STR_NOALIGN means don't try to align -if STR_TERMINATE is set then src_len is ignored if it is -1 -src_len is the length of the source area in bytes -return the number of bytes occupied by the string in src -the resulting string in "dest" is always null terminated + Copy a string from a ucs2 source to a unix char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_NOALIGN means don't try to align. + if STR_TERMINATE is set then src_len is ignored if it is -1. + src_len is the length of the source area in bytes + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. ****************************************************************************/ -int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, int flags) + +size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { - int ret; + size_t ret; - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (ucs2_align(base_ptr, src, flags)) { src = (const void *)((const char *)src + 1); - if (src_len > 0) src_len--; + if (src_len > 0) + src_len--; } if (flags & STR_TERMINATE) { - if (src_len == -1) { + if (src_len == (size_t)-1) { src_len = strlen_w(src)*2 + 2; } else { - int len = strnlen_w(src, src_len/2); - if (len < src_len/2) len++; + size_t len = strnlen_w(src, src_len/2); + if (len < src_len/2) + len++; src_len = len*2; } } /* ucs2 is always a multiple of 2 bytes */ - if (src_len != -1) + if (src_len != (size_t)-1) src_len &= ~1; ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; return src_len; } -int pull_ucs2_pstring(char *dest, const void *src) +size_t pull_ucs2_pstring(char *dest, const void *src) { return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); } -int pull_ucs2_fstring(char *dest, const void *src) +size_t pull_ucs2_fstring(char *dest, const void *src) { return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); } @@ -590,9 +604,10 @@ int pull_ucs2_fstring(char *dest, const void *src) * * @retval The number of bytes occupied by the string in the destination **/ -int pull_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) + +size_t pull_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const smb_ucs2_t *src) { - int src_len = strlen(src)+1; + size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, dest); } @@ -604,52 +619,55 @@ int pull_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int pull_ucs2_allocate(void **dest, const char *src) + +size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) { - int src_len = strlen(src)+1; + size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); } /**************************************************************************** -copy a string from a utf-8 source to a unix char* destination -flags can have: - STR_TERMINATE means the string in src is null terminated -if STR_TERMINATE is set then src_len is ignored -src_len is the length of the source area in bytes -return the number of bytes occupied by the string in src -the resulting string in "dest" is always null terminated + Copy a string from a utf-8 source to a unix char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + if STR_TERMINATE is set then src_len is ignored. + src_len is the length of the source area in bytes + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. ****************************************************************************/ -int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) + +size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { - int ret; + size_t ret; - if (dest_len == -1) { + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - } if (flags & STR_TERMINATE) { - if (src_len == -1) { + if (src_len == (size_t)-1) { src_len = strlen(src) + 1; } else { - int len = strnlen(src, src_len); - if (len < src_len) len++; + size_t len = strnlen(src, src_len); + if (len < src_len) + len++; src_len = len; } } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; return src_len; } -int pull_utf8_pstring(char *dest, const void *src) +size_t pull_utf8_pstring(char *dest, const void *src) { return pull_utf8(dest, src, sizeof(pstring), -1, STR_TERMINATE); } -int pull_utf8_fstring(char *dest, const void *src) +size_t pull_utf8_fstring(char *dest, const void *src) { return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE); } @@ -661,9 +679,10 @@ int pull_utf8_fstring(char *dest, const void *src) * * @retval The number of bytes occupied by the string in the destination **/ -int pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) + +size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); } @@ -675,27 +694,29 @@ int pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * * @retval The number of bytes occupied by the string in the destination **/ -int pull_utf8_allocate(void **dest, const char *src) + +size_t pull_utf8_allocate(void **dest, const char *src) { - int src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest); } /**************************************************************************** -copy a string from a char* src to a unicode or ascii -dos codepage destination choosing unicode or ascii based on the -flags in the SMB buffer starting at base_ptr -return the number of bytes occupied by the string in the destination -flags can have: - STR_TERMINATE means include the null termination - STR_UPPER means uppercase in the destination - STR_ASCII use ascii even with unicode packet - STR_NOALIGN means don't do alignment -dest_len is the maximum length allowed in the destination. If dest_len -is -1 then no maxiumum is used + Copy a string from a char* src to a unicode or ascii + dos codepage destination choosing unicode or ascii based on the + flags in the SMB buffer starting at base_ptr. + Return the number of bytes occupied by the string in the destination. + flags can have: + STR_TERMINATE means include the null termination. + STR_UPPER means uppercase in the destination. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + dest_len is the maximum length allowed in the destination. If dest_len + is -1 then no maxiumum is used. ****************************************************************************/ -int push_string(const void *base_ptr, void *dest, const char *src, int dest_len, int flags) + +size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ @@ -707,20 +728,20 @@ int push_string(const void *base_ptr, void *dest, const char *src, int dest_len, /**************************************************************************** -copy a string from a unicode or ascii source (depending on -the packet flags) to a char* destination -flags can have: - STR_TERMINATE means the string in src is null terminated - STR_UNICODE means to force as unicode - STR_ASCII use ascii even with unicode packet - STR_NOALIGN means don't do alignment -if STR_TERMINATE is set then src_len is ignored is it is -1 -src_len is the length of the source area in bytes -return the number of bytes occupied by the string in src -the resulting string in "dest" is always null terminated + Copy a string from a unicode or ascii source (depending on + the packet flags) to a char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_UNICODE means to force as unicode. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + if STR_TERMINATE is set then src_len is ignored is it is -1 + src_len is the length of the source area in bytes. + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. ****************************************************************************/ -int pull_string(const void *base_ptr, char *dest, const void *src, int dest_len, int src_len, - int flags) + +size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ @@ -730,7 +751,7 @@ int pull_string(const void *base_ptr, char *dest, const void *src, int dest_len, return pull_ascii(dest, src, dest_len, src_len, flags); } -int align_string(const void *base_ptr, const char *p, int flags) +size_t align_string(const void *base_ptr, const char *p, int flags) { if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ @@ -740,14 +761,13 @@ int align_string(const void *base_ptr, const char *p, int flags) return 0; } - - /**************************************************************************** -convert from ucs2 to unix charset and return the -allocated and converted string or NULL if an error occurred. -you must provide a zero terminated string. -the returning string will be zero terminated. + Convert from ucs2 to unix charset and return the + allocated and converted string or NULL if an error occurred. + You must provide a zero terminated string. + The returning string will be zero terminated. ****************************************************************************/ + char *acnv_u2ux(const smb_ucs2_t *src) { size_t slen; @@ -756,16 +776,19 @@ char *acnv_u2ux(const smb_ucs2_t *src) slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); - if (dlen == -1) return NULL; - else return dest; + if (dlen == (size_t)-1) + return NULL; + else + return dest; } /**************************************************************************** -convert from unix to ucs2 charset and return the -allocated and converted string or NULL if an error occurred. -you must provide a zero terminated string. -the returning string will be zero terminated. + Convert from unix to ucs2 charset and return the + allocated and converted string or NULL if an error occurred. + You must provide a zero terminated string. + The returning string will be zero terminated. ****************************************************************************/ + smb_ucs2_t *acnv_uxu2(const char *src) { size_t slen; @@ -774,16 +797,19 @@ smb_ucs2_t *acnv_uxu2(const char *src) slen = strlen(src) + 1; dlen = convert_string_allocate(CH_UNIX, CH_UCS2, src, slen, &dest); - if (dlen == -1) return NULL; - else return dest; + if (dlen == (size_t)-1) + return NULL; + else + return dest; } /**************************************************************************** -convert from ucs2 to dos charset and return the -allocated and converted string or NULL if an error occurred. -you must provide a zero terminated string. -the returning string will be zero terminated. + Convert from ucs2 to dos charset and return the + allocated and converted string or NULL if an error occurred. + You must provide a zero terminated string. + The returning string will be zero terminated. ****************************************************************************/ + char *acnv_u2dos(const smb_ucs2_t *src) { size_t slen; @@ -792,16 +818,19 @@ char *acnv_u2dos(const smb_ucs2_t *src) slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); dlen = convert_string_allocate(CH_UCS2, CH_DOS, src, slen, &dest); - if (dlen == -1) return NULL; - else return dest; + if (dlen == (size_t)-1) + return NULL; + else + return dest; } /**************************************************************************** -convert from dos to ucs2 charset and return the -allocated and converted string or NULL if an error occurred. -you must provide a zero terminated string. -the returning string will be zero terminated. + Convert from dos to ucs2 charset and return the + allocated and converted string or NULL if an error occurred. + You must provide a zero terminated string. + The returning string will be zero terminated. ****************************************************************************/ + smb_ucs2_t *acnv_dosu2(const char *src) { size_t slen; @@ -810,6 +839,8 @@ smb_ucs2_t *acnv_dosu2(const char *src) slen = strlen(src) + 1; dlen = convert_string_allocate(CH_DOS, CH_UCS2, src, slen, &dest); - if (dlen == -1) return NULL; - else return dest; + if (dlen == (size_t)-1) + return NULL; + else + return dest; } -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/lib/charcnv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 04145fd17a..3428377d95 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -30,9 +30,9 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; Return the name of a charset to give to iconv(). ****************************************************************************/ -static char *charset_name(charset_t ch) +static const char *charset_name(charset_t ch) { - char *ret = NULL; + const char *ret = NULL; if (ch == CH_UCS2) ret = "UCS-2LE"; else if (ch == CH_UNIX) ret = lp_unix_charset(); @@ -75,8 +75,8 @@ void init_iconv(void) for (c1=0;c1from_name) == 0 && strcmp(n2, conv_handles[c1][c2]->to_name) == 0) @@ -140,7 +140,7 @@ size_t convert_string(charset_t from, charset_t to, o_len=destlen; retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); if(retval==-1) { - char *reason="unknown error"; + const char *reason="unknown error"; switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; @@ -215,7 +215,7 @@ convert: &inbuf, &i_len, &outbuf, &o_len); if(retval == -1) { - char *reason="unknown error"; + const char *reason="unknown error"; switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; -- cgit From 3b2244526c7ae64f744539154681b9883daebc3f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 1 Feb 2003 07:25:53 +0000 Subject: Merge of signed/unsigned fixes from HEAD. (This used to be commit e9f56a157bd472914eebf64fde586104d8274717) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 3428377d95..6dd3cd52d9 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -139,7 +139,7 @@ size_t convert_string(charset_t from, charset_t to, i_len=srclen; o_len=destlen; retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); - if(retval==-1) { + if(retval==(size_t)-1) { const char *reason="unknown error"; switch(errno) { case EINVAL: @@ -214,7 +214,7 @@ convert: retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); - if(retval == -1) { + if(retval == (size_t)-1) { const char *reason="unknown error"; switch(errno) { case EINVAL: -- cgit From cba08587d39654e3b64ff6c0977d44f4b77b24bc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Feb 2003 01:09:35 +0000 Subject: Merge from HEAD - pull_ucs2_talloc() should pull to a char**, not a void** Jeremy. (This used to be commit 81437e2ad034e9b83ae954c17a7a261504c55101) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6dd3cd52d9..54e17bea68 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -605,11 +605,11 @@ size_t pull_ucs2_fstring(char *dest, const void *src) * @retval The number of bytes occupied by the string in the destination **/ -size_t pull_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const smb_ucs2_t *src) +size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, dest); + return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest); } /** -- cgit From 0fc93128b8e510c3ccc161044068d9f3960635da Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 24 Feb 2003 01:10:15 +0000 Subject: Add comment about Samba character sets, from explanation by abartlet. (This used to be commit 822f6c2f38b9b30dca2358e99ad6a379f5890c89) --- source3/lib/charcnv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 54e17bea68..4ac10a2e74 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,6 +22,19 @@ */ #include "includes.h" +/** + * @file + * + * @brief Character-set conversion routines built on our iconv. + * + * @note Samba's internal character set (at least in the 3.0 series) + * is always the same as the one for the Unix filesystem. It is + * not necessarily UTF-8 and may be different on machines that + * need i18n filenames to be compatible with Unix software. It does + * have to be a superset of ASCII. All multibyte sequences must start + * with a byte with the high bit set. + */ + static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -- cgit From 266ec4aac04cb8666234f18baa38ff6387f40cb3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 03:09:08 +0000 Subject: Merge doxygen, signed/unsigned, const and other small fixes from HEAD to 3.0. Andrew Bartlett (This used to be commit 9ef0d40c3f8aef52ab321dc065264c42065bc876) --- source3/lib/charcnv.c | 175 ++++++++++++++++++++++++++------------------------ 1 file changed, 92 insertions(+), 83 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4ac10a2e74..bffa2a378c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,27 +22,22 @@ */ #include "includes.h" -/** - * @file - * - * @brief Character-set conversion routines built on our iconv. - * - * @note Samba's internal character set (at least in the 3.0 series) - * is always the same as the one for the Unix filesystem. It is - * not necessarily UTF-8 and may be different on machines that - * need i18n filenames to be compatible with Unix software. It does - * have to be a superset of ASCII. All multibyte sequences must start - * with a byte with the high bit set. - */ - static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -/**************************************************************************** - Return the name of a charset to give to iconv(). -****************************************************************************/ +/** + * @file + * + * Character set conversion routines. + * + * @sa lib/iconv.c + **/ + +/** + * Return the name of a charset to give to iconv(). + **/ static const char *charset_name(charset_t ch) { const char *ret = NULL; @@ -69,9 +64,9 @@ static void lazy_initialize_conv(void) } } -/**************************************************************************** +/** Initialize iconv conversion descriptors. -****************************************************************************/ +**/ void init_iconv(void) { @@ -117,14 +112,12 @@ void init_iconv(void) /** * Convert string from one encoding to another, making error checking etc * - * @param descriptor conversion descriptor, created in init_iconv() * @param src pointer to source string (multibyte or singlebyte) * @param srclen length of the source string in bytes * @param dest pointer to destination string (multibyte or singlebyte) * @param destlen maximal length allowed for string - * @retval the number of bytes occupied in the destination + * @returns the number of bytes occupied in the destination **/ - size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) @@ -183,7 +176,7 @@ size_t convert_string(charset_t from, charset_t to, * @param dest always set at least to NULL * @note -1 is not accepted for srclen. * - * @retval Size in bytes of the converted string; or -1 in case of error. + * @returns Size in bytes of the converted string; or -1 in case of error. **/ size_t convert_string_allocate(charset_t from, charset_t to, @@ -255,6 +248,7 @@ convert: return destlen; } + /** * Convert between character sets, allocating a new buffer using talloc for the result. * @@ -262,9 +256,8 @@ convert: * @param dest always set at least to NULL * @note -1 is not accepted for srclen. * - * @retval Size in bytes of the converted string; or -1 in case of error. + * @returns Size in bytes of the converted string; or -1 in case of error. **/ - size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { @@ -311,16 +304,20 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags) } -/**************************************************************************** -copy a string from a char* unix src to a dos codepage string destination -return the number of bytes occupied by the string in the destination -flags can have: - STR_TERMINATE means include the null termination - STR_UPPER means uppercase in the destination -dest_len is the maximum length in bytes allowed in the destination. If dest_len -is -1 then no maxiumum is used -****************************************************************************/ - +/** + * Copy a string from a char* unix src to a dos codepage string destination. + * + * @return the number of bytes occupied by the string in the destination. + * + * @param flags can include + *
+ *
STR_TERMINATE
means include the null termination
+ *
STR_UPPER
means uppercase in the destination
+ *
+ * + * @param dest_len the maximum length in bytes allowed in the + * destination. If @p dest_len is -1 then no maximum is used. + **/ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); @@ -357,16 +354,21 @@ size_t push_pstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } -/**************************************************************************** - Copy a string from a dos codepage source to a unix char* destination. - Flags can have: - STR_TERMINATE means the string in src is null terminated. - if STR_TERMINATE is set then src_len is ignored. - src_len is the length of the source area in bytes. - Return the number of bytes occupied by the string in src. - The resulting string in "dest" is always null terminated. -****************************************************************************/ - +/** + * Copy a string from a dos codepage source to a unix char* destination. + * + * The resulting string in "dest" is always null terminated. + * + * @param flags can have: + *
+ *
STR_TERMINATE
+ *
STR_TERMINATE means the string in @p src + * is null terminated, and src_len is ignored.
+ *
+ * + * @param src_len is the length of the source area in bytes. + * @returns the number of bytes occupied by the string in @p src. + **/ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -403,17 +405,22 @@ size_t pull_ascii_fstring(char *dest, const void *src) return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } -/**************************************************************************** - Copy a string from a char* src to a unicode destination. - Return the number of bytes occupied by the string in the destination. - Flags can have: - STR_TERMINATE means include the null termination. - STR_UPPER means uppercase in the destination. - STR_NOALIGN means don't do alignment. - dest_len is the maximum length allowed in the destination. If dest_len - is -1 then no maxiumum is used. -****************************************************************************/ - +/** + * Copy a string from a char* src to a unicode destination. + * + * @returns the number of bytes occupied by the string in the destination. + * + * @param flags can have: + * + *
+ *
STR_TERMINATE
means include the null termination. + *
STR_UPPER
means uppercase in the destination. + *
STR_NOALIGN
means don't do alignment. + *
+ * + * @param dest_len is the maximum length allowed in the + * destination. If dest_len is -1 then no maxiumum is used. + **/ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; @@ -447,15 +454,16 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ return len; } + /** - * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer using talloc + * Copy a string from a unix char* src to a UCS2 destination, + * allocating a buffer using talloc(). * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination * or -1 in case of error. **/ - size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) { size_t src_len = strlen(src)+1; @@ -464,12 +472,13 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } + /** * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination * or -1 in case of error. **/ @@ -481,7 +490,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } -/**************************************************************************** +/** Copy a string from a char* src to a UTF-8 destination. Return the number of bytes occupied by the string in the destination Flags can have: @@ -489,7 +498,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) STR_UPPER means uppercase in the destination dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used. -****************************************************************************/ +**/ size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) { @@ -527,7 +536,7 @@ size_t push_utf8_pstring(void *dest, const char *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) @@ -543,7 +552,7 @@ size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t push_utf8_allocate(char **dest, const char *src) @@ -554,7 +563,7 @@ size_t push_utf8_allocate(char **dest, const char *src) return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } -/**************************************************************************** +/** Copy a string from a ucs2 source to a unix char* destination. Flags can have: STR_TERMINATE means the string in src is null terminated. @@ -563,7 +572,7 @@ size_t push_utf8_allocate(char **dest, const char *src) src_len is the length of the source area in bytes Return the number of bytes occupied by the string in src. The resulting string in "dest" is always null terminated. -****************************************************************************/ +**/ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { @@ -615,7 +624,7 @@ size_t pull_ucs2_fstring(char *dest, const void *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) @@ -630,7 +639,7 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) @@ -640,7 +649,7 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); } -/**************************************************************************** +/** Copy a string from a utf-8 source to a unix char* destination. Flags can have: STR_TERMINATE means the string in src is null terminated. @@ -648,7 +657,7 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) src_len is the length of the source area in bytes Return the number of bytes occupied by the string in src. The resulting string in "dest" is always null terminated. -****************************************************************************/ +**/ size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { @@ -690,7 +699,7 @@ size_t pull_utf8_fstring(char *dest, const void *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) @@ -705,7 +714,7 @@ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * * @param dest always set at least to NULL * - * @retval The number of bytes occupied by the string in the destination + * @returns The number of bytes occupied by the string in the destination **/ size_t pull_utf8_allocate(void **dest, const char *src) @@ -715,7 +724,7 @@ size_t pull_utf8_allocate(void **dest, const char *src) return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest); } -/**************************************************************************** +/** Copy a string from a char* src to a unicode or ascii dos codepage destination choosing unicode or ascii based on the flags in the SMB buffer starting at base_ptr. @@ -727,7 +736,7 @@ size_t pull_utf8_allocate(void **dest, const char *src) STR_NOALIGN means don't do alignment. dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used. -****************************************************************************/ +**/ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { @@ -740,7 +749,7 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des } -/**************************************************************************** +/** Copy a string from a unicode or ascii source (depending on the packet flags) to a char* destination. Flags can have: @@ -752,7 +761,7 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des src_len is the length of the source area in bytes. Return the number of bytes occupied by the string in src. The resulting string in "dest" is always null terminated. -****************************************************************************/ +**/ size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { @@ -774,12 +783,12 @@ size_t align_string(const void *base_ptr, const char *p, int flags) return 0; } -/**************************************************************************** +/** Convert from ucs2 to unix charset and return the allocated and converted string or NULL if an error occurred. You must provide a zero terminated string. The returning string will be zero terminated. -****************************************************************************/ +**/ char *acnv_u2ux(const smb_ucs2_t *src) { @@ -795,12 +804,12 @@ char *acnv_u2ux(const smb_ucs2_t *src) return dest; } -/**************************************************************************** +/** Convert from unix to ucs2 charset and return the allocated and converted string or NULL if an error occurred. You must provide a zero terminated string. The returning string will be zero terminated. -****************************************************************************/ +**/ smb_ucs2_t *acnv_uxu2(const char *src) { @@ -816,12 +825,12 @@ smb_ucs2_t *acnv_uxu2(const char *src) return dest; } -/**************************************************************************** +/** Convert from ucs2 to dos charset and return the allocated and converted string or NULL if an error occurred. You must provide a zero terminated string. The returning string will be zero terminated. -****************************************************************************/ +**/ char *acnv_u2dos(const smb_ucs2_t *src) { @@ -837,12 +846,12 @@ char *acnv_u2dos(const smb_ucs2_t *src) return dest; } -/**************************************************************************** +/** Convert from dos to ucs2 charset and return the allocated and converted string or NULL if an error occurred. You must provide a zero terminated string. The returning string will be zero terminated. -****************************************************************************/ +**/ smb_ucs2_t *acnv_dosu2(const char *src) { -- cgit From 1a2035a8f529e7831754fd8e0fc07dd2222deddd Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 24 Feb 2003 04:49:10 +0000 Subject: Merge documentation from HEAD (This used to be commit 3761f8ebe339fbbeffee9d7b69f9483ebfd9ae6b) --- source3/lib/charcnv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index bffa2a378c..a8df003f8b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,17 +22,24 @@ */ #include "includes.h" -static pstring cvtbuf; - -static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; - /** * @file * - * Character set conversion routines. + * @brief Character-set conversion routines built on our iconv. + * + * @note Samba's internal character set (at least in the 3.0 series) + * is always the same as the one for the Unix filesystem. It is + * not necessarily UTF-8 and may be different on machines that + * need i18n filenames to be compatible with Unix software. It does + * have to be a superset of ASCII. All multibyte sequences must start + * with a byte with the high bit set. * * @sa lib/iconv.c - **/ + */ + +static pstring cvtbuf; + +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /** -- cgit From d332200c254b4bbf27461a37f9655bf42faa2b3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Mar 2003 01:48:11 +0000 Subject: Merge in the developer string options from HEAD. We need to ensure 3.0 is as stable as possible in the string department and some pain now will help later :-). Jeremy. (This used to be commit 86e3eddac698d90f4666b8492b4603a4efbbd67b) --- source3/lib/charcnv.c | 115 ++++++-------------------------------------------- 1 file changed, 12 insertions(+), 103 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a8df003f8b..fa646573d8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -186,7 +186,7 @@ size_t convert_string(charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. **/ -size_t convert_string_allocate(charset_t from, charset_t to, +static size_t convert_string_allocate(charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { size_t i_len, o_len, destlen; @@ -265,7 +265,7 @@ convert: * * @returns Size in bytes of the converted string; or -1 in case of error. **/ -size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, +static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { void *alloced_string; @@ -303,7 +303,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) } -size_t ucs2_align(const void *base_ptr, const void *p, int flags) +static size_t ucs2_align(const void *base_ptr, const void *p, int flags) { if (flags & (STR_NOALIGN|STR_ASCII)) return 0; @@ -356,11 +356,6 @@ size_t push_ascii_pstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } -size_t push_pstring(void *dest, const char *src) -{ - return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); -} - /** * Copy a string from a dos codepage source to a unix char* destination. * @@ -507,7 +502,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) is -1 then no maxiumum is used. **/ -size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) +static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); pstring tmpbuf; @@ -533,11 +528,6 @@ size_t push_utf8_fstring(void *dest, const char *src) return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE); } -size_t push_utf8_pstring(void *dest, const char *src) -{ - return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE); -} - /** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * @@ -656,51 +646,6 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); } -/** - Copy a string from a utf-8 source to a unix char* destination. - Flags can have: - STR_TERMINATE means the string in src is null terminated. - if STR_TERMINATE is set then src_len is ignored. - src_len is the length of the source area in bytes - Return the number of bytes occupied by the string in src. - The resulting string in "dest" is always null terminated. -**/ - -size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) -{ - size_t ret; - - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - - if (flags & STR_TERMINATE) { - if (src_len == (size_t)-1) { - src_len = strlen(src) + 1; - } else { - size_t len = strnlen(src, src_len); - if (len < src_len) - len++; - src_len = len; - } - } - - ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - - return src_len; -} - -size_t pull_utf8_pstring(char *dest, const void *src) -{ - return pull_utf8(dest, src, sizeof(pstring), -1, STR_TERMINATE); -} - -size_t pull_utf8_fstring(char *dest, const void *src) -{ - return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE); -} - /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * @@ -745,8 +690,11 @@ size_t pull_utf8_allocate(void **dest, const char *src) is -1 then no maxiumum is used. **/ -size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) +size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { + if (dest_len != (size_t)-1) + clobber_region(function, line, dest, dest_len); + if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { @@ -770,8 +718,11 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des The resulting string in "dest" is always null terminated. **/ -size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { + if (dest_len != (size_t)-1) + clobber_region(function, line, dest, dest_len); + if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { @@ -790,27 +741,6 @@ size_t align_string(const void *base_ptr, const char *p, int flags) return 0; } -/** - Convert from ucs2 to unix charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -char *acnv_u2ux(const smb_ucs2_t *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); - dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} - /** Convert from unix to ucs2 charset and return the allocated and converted string or NULL if an error occurred. @@ -832,27 +762,6 @@ smb_ucs2_t *acnv_uxu2(const char *src) return dest; } -/** - Convert from ucs2 to dos charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -char *acnv_u2dos(const smb_ucs2_t *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); - dlen = convert_string_allocate(CH_UCS2, CH_DOS, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} - /** Convert from dos to ucs2 charset and return the allocated and converted string or NULL if an error occurred. -- cgit From 0b72dd8325bc5c78de56039942acc175d28042a7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Mar 2003 16:44:14 +0000 Subject: Patch from Samuel Thibault to convert messages from dos to unix charset when sending(and vice versa when receiving). (This used to be commit 5310447ec6e0df1c000e3ee14572f5b7fee31f28) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index fa646573d8..42cba33483 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -186,7 +186,7 @@ size_t convert_string(charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. **/ -static size_t convert_string_allocate(charset_t from, charset_t to, +size_t convert_string_allocate(charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { size_t i_len, o_len, destlen; -- cgit From b5e7b9dbeadfd64e28e4b837222703b4060fb7f9 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 4 Apr 2003 07:50:59 +0000 Subject: lazy_initialize_conv: Remove redundant call to init_valid_table, because init_iconv calls it for us. init_iconv: Add documentation about how this is reintialized when configuration is reloaded. (This used to be commit 0ee80a9018601fbba1c9558545de61cb16e94fac) --- source3/lib/charcnv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 42cba33483..dc270b94b7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -67,14 +67,16 @@ static void lazy_initialize_conv(void) initialized = True; load_case_tables(); init_iconv(); - init_valid_table(); } } /** - Initialize iconv conversion descriptors. -**/ - + * Initialize iconv conversion descriptors. + * + * This is called the first time it is needed, and also called again + * every time the configuration is reloaded, because the charset or + * codepage might have changed. + **/ void init_iconv(void) { int c1, c2; -- cgit From 4127c455c8fd446ab952de37fabbd7d8ef20847a Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 4 Apr 2003 08:25:05 +0000 Subject: Export lazy_initialize_conv so that it can be called from check_dos_char. init_iconv: Call init_doschar_table when reinitializing conversions. (This used to be commit d0b2c5d7ba5531fc695a23bba87a1551cc39e2ee) --- source3/lib/charcnv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index dc270b94b7..00670f4a85 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -59,7 +59,7 @@ static const char *charset_name(charset_t ch) return ret; } -static void lazy_initialize_conv(void) +void lazy_initialize_conv(void) { static int initialized = False; @@ -114,6 +114,10 @@ void init_iconv(void) } if (did_reload) { + /* XXX: Does this really get called every time the dos + * codepage changes? */ + /* XXX: Is the did_reload test too strict? */ + init_doschar_table(); init_valid_table(); } } -- cgit From ee7f29a9f8c5705e66b1ca10babb46763d413657 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 14 Apr 2003 11:04:57 +0000 Subject: Merge across tridge's Realloc fix. Jeremy. (This used to be commit df214d18817467fbe3023a412bceec325f73b518) --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 00670f4a85..8b93e30267 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -220,14 +220,14 @@ size_t convert_string_allocate(charset_t from, charset_t to, outbuf = NULL; convert: destlen = destlen * 2; - ob = (char *)realloc(outbuf, destlen); + ob = (char *)Realloc(outbuf, destlen); if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); SAFE_FREE(outbuf); return (size_t)-1; - } - else + } else { outbuf = ob; + } i_len = srclen; o_len = destlen; retval = smb_iconv(descriptor, -- cgit From bc83d3a4edcc5ce0483b7248cf6498a088e8d1d1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 22 Apr 2003 13:15:24 +0000 Subject: Merge (HEAD->3.0) mbp's fixes to our charcnv code - don't use a staic buffer, which can restrict things like unix_strupper() to 512 byte strings. Andrew Bartlett (This used to be commit 341d6affa474262654f83c075f186d985cbcb9a0) --- source3/lib/charcnv.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 8b93e30267..7acb7147fd 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -4,6 +4,7 @@ Copyright (C) Igor Vergeichik 2001 Copyright (C) Andrew Tridgell 2001 Copyright (C) Simo Sorce 2001 + Copyright (C) Martin Pool 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 @@ -37,7 +38,6 @@ * @sa lib/iconv.c */ -static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; @@ -193,7 +193,7 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(charset_t from, charset_t to, - void const *src, size_t srclen, void **dest) + void const *src, size_t srclen, void **dest) { size_t i_len, o_len, destlen; size_t retval; @@ -277,6 +277,8 @@ static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t t void *alloced_string; size_t dest_len; + /* FIXME: Ridiculous to allocate two buffers and then copy the string! */ + *dest = NULL; dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string); if (dest_len == (size_t)-1) @@ -291,21 +293,40 @@ static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t t size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strupper_w(buffer) && (dest == src)) + smb_ucs2_t *buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, + (void **) &buffer); + if (size == -1) { + smb_panic("failed to create UCS2 buffer"); + } + if (!strupper_w(buffer) && (dest == src)) { + free(buffer); return srclen; - return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + } + + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + free(buffer); + return size; } size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strlower_w(buffer) && (dest == src)) + smb_ucs2_t *buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, + (void **) &buffer); + if (size == -1) { + smb_panic("failed to create UCS2 buffer"); + } + if (!strlower_w(buffer) && (dest == src)) { + free(buffer); return srclen; - return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + } + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + free(buffer); + return size; } @@ -645,11 +666,11 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) * @returns The number of bytes occupied by the string in the destination **/ -size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) +size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); + return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, (void **)dest); } /** -- cgit From 66468d23158694383f3759464ffa7ade1c1d6d6c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Apr 2003 14:07:33 +0000 Subject: Patch by Metze to ensure that we always at least initialize our output string for rpc_pull_string. If we had a NULL or zero-length string, we would use uninitialised data in the result string. Andrew Bartlett (This used to be commit df10aee451b431a8a056a949a98393da256185da) --- source3/lib/charcnv.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7acb7147fd..5086f924db 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -420,6 +420,8 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + else + dest[0] = 0; return src_len; } @@ -629,6 +631,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + else + dest[0] = 0; return src_len; } -- cgit From 03412f056d7a277aab8cf6c3daa850803ae74126 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 28 Apr 2003 05:47:07 +0000 Subject: Whitespace syncup. (This used to be commit 7fd7af121ee8ba4f9540394f64fe3c78e2e96cd2) --- source3/lib/charcnv.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5086f924db..7acb7147fd 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -420,8 +420,6 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (dest_len) dest[MIN(ret, dest_len-1)] = 0; - else - dest[0] = 0; return src_len; } @@ -631,8 +629,6 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; - else - dest[0] = 0; return src_len; } -- cgit From 22fb803b39ec5deddcd4bc941508f01d005e463f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 7 May 2003 05:52:44 +0000 Subject: Whoops - that wasn't a whitespace syncup after all. (This used to be commit 42d0414ed244b92b665cb231f6756f60391861dd) --- source3/lib/charcnv.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7acb7147fd..102b77592b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -629,6 +629,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + else + dest[0] = 0; return src_len; } -- cgit From bbdc326f15894293c7730a73151c8ad02b58d4e7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 8 May 2003 05:10:44 +0000 Subject: Another attempt at undoing my bogus patch 1.55.2.19 (This used to be commit 05a684b3be1525aad3589ded9e59c3f012b5ef20) --- source3/lib/charcnv.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 102b77592b..febd7d5496 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -420,6 +420,8 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (dest_len) dest[MIN(ret, dest_len-1)] = 0; + else + dest[0] = 0; return src_len; } -- cgit From 27d68a306d1e816c95865671755398b4e04cf5b2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 8 May 2003 20:19:10 +0000 Subject: fixed bug #75; add check for non-zero destlen (This used to be commit 83bb84f13121267992e78f2d005257932c711f23) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index febd7d5496..eb427cc0fc 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -252,7 +252,7 @@ convert: destlen = destlen - o_len; *dest = (char *)Realloc(ob,destlen); - if (!*dest) { + if (destlen && !*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); SAFE_FREE(ob); return (size_t)-1; -- cgit From 6b943b5b2188314739f4f36541f1ef469ba9a3b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jun 2003 05:15:28 +0000 Subject: - the 8.3 name in BOTH_DIRECTORY_INFO is supposed to be always unicode (to match win2003 behaviour) - added the STR_TERMINATE_ASCII flag from samba4 so we can get the string termination right for the case where it is supposed to be non-terminated for UCS2 and terminated when ASCII (This used to be commit 791a4cc7cf84eca77116bca00aeb5f95560f6705) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index eb427cc0fc..1a74318439 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -367,7 +367,7 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) src = tmpbuf; } - if (flags & STR_TERMINATE) + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) src_len++; return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); -- cgit From 0bbbe382a5b9d9906050629f531424b251302acf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Jun 2003 07:56:23 +0000 Subject: Fix for valgrind - when doing a srvstr_push we must zero fill any extra bytes, not clobber region them - otherwise valgrind thinks they are invalid on send() or write(). Jeremy. (This used to be commit 8aa5f7a65c71fb89ed05e71a2465e61385e80c2b) --- source3/lib/charcnv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 1a74318439..708ef343e1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -723,8 +723,21 @@ size_t pull_utf8_allocate(void **dest, const char *src) size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { +#ifdef DEVELOPER + /* We really need to zero fill here, not clobber + * region, as we want to ensure that valgrind thinks + * all of the outgoing buffer has been written to + * so a send() or write() won't trap an error. + * JRA. + */ +#if 0 if (dest_len != (size_t)-1) clobber_region(function, line, dest, dest_len); +#else + if (dest_len != (size_t)-1) + memset(dest, '\0', dest_len); +#endif +#endif if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ -- cgit From 489956c82391d7559bb097b112957e6a7d91934c Mon Sep 17 00:00:00 2001 From: John Terpstra Date: Sun, 15 Jun 2003 06:07:53 +0000 Subject: Patch from vorlon@debian.org, see bugzilal #122 Samba should preferentially use the locale information from the native system, and only fall back on 'display charset' if this is unavailable or unsupported. (This used to be commit 1e445fb4220cdf4700dd9d1850a42746a1065c5a) --- source3/lib/charcnv.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 708ef343e1..b37f468134 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -90,10 +90,28 @@ void init_iconv(void) if (!conv_handles[CH_UCS2][CH_UNIX]) conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif + for (c1=0;c1from_name) == 0 && + strcmp(n2, conv_handles[c1][c2]->to_name) == 0) + continue; + + if (c2==CH_DISPLAY && conv_handles[c1][c2] && + strcmp(n1, conv_handles[c1][c2]->from_name) == 0 && + strcmp(ln, conv_handles[c1][c2]->to_name) == 0) + continue; + +#endif if (conv_handles[c1][c2] && strcmp(n1, conv_handles[c1][c2]->from_name) == 0 && strcmp(n2, conv_handles[c1][c2]->to_name) == 0) @@ -104,6 +122,25 @@ void init_iconv(void) if (conv_handles[c1][c2]) smb_iconv_close(conv_handles[c1][c2]); +#ifdef HAVE_NL_LANGINFO + if (c1==CH_DISPLAY && c2==CH_DISPLAY) { + conv_handles[c1][c2] = smb_iconv_open(ln,ln); + if (conv_handles[c1][c2] != (smb_iconv_t)-1) { + continue; + } + } else if (c1==CH_DISPLAY) { + conv_handles[c1][c2] = smb_iconv_open(n2,ln); + if (conv_handles[c1][c2] != (smb_iconv_t)-1) { + continue; + } + } else if (c2==CH_DISPLAY) { + conv_handles[c1][c2] = smb_iconv_open(ln,n1); + if (conv_handles[c1][c2] != (smb_iconv_t)-1) { + continue; + } + } + /* Fall back to the configured charset. */ +#endif conv_handles[c1][c2] = smb_iconv_open(n2,n1); if (conv_handles[c1][c2] == (smb_iconv_t)-1) { DEBUG(0,("Conversion from %s to %s not supported\n", -- cgit From 8cd67d76683a41a1db5efc3a9c65e056ec2263f4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Jun 2003 02:22:52 +0000 Subject: reverted locale patch put in by jht (originally from vorlon). There are lots of things wrong with this patch, including: 1) it overrides a user chosen configuration option 2) it adds lots of complexity inside a loop when a tiny piece of code outside the loop would do the same thing 3) it does no error checking, and is sure to crash on some systems If you want this functionality then try something like this at the end of charset_name(): #ifdef HAVE_NL_LANGINFO if (strcasecmp(ret, "LOCALE") == 0) { const char *ln = nl_langinfo(CODESET); if (ln) { DEBUG(5,("Substituting charset '%s' for LOCALE\n", ln)); return ln; } } #endif then users can set 'display charset = LOCALE' to get the locale based charset. You could even make that the default for systems that have nl_langinfo(). (This used to be commit 382b9b806b1ecd227b1ea247e3825d6848090462) --- source3/lib/charcnv.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b37f468134..708ef343e1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -90,28 +90,10 @@ void init_iconv(void) if (!conv_handles[CH_UCS2][CH_UNIX]) conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); -#ifdef HAVE_SETLOCALE - setlocale(LC_ALL, ""); -#endif - for (c1=0;c1from_name) == 0 && - strcmp(n2, conv_handles[c1][c2]->to_name) == 0) - continue; - - if (c2==CH_DISPLAY && conv_handles[c1][c2] && - strcmp(n1, conv_handles[c1][c2]->from_name) == 0 && - strcmp(ln, conv_handles[c1][c2]->to_name) == 0) - continue; - -#endif if (conv_handles[c1][c2] && strcmp(n1, conv_handles[c1][c2]->from_name) == 0 && strcmp(n2, conv_handles[c1][c2]->to_name) == 0) @@ -122,25 +104,6 @@ void init_iconv(void) if (conv_handles[c1][c2]) smb_iconv_close(conv_handles[c1][c2]); -#ifdef HAVE_NL_LANGINFO - if (c1==CH_DISPLAY && c2==CH_DISPLAY) { - conv_handles[c1][c2] = smb_iconv_open(ln,ln); - if (conv_handles[c1][c2] != (smb_iconv_t)-1) { - continue; - } - } else if (c1==CH_DISPLAY) { - conv_handles[c1][c2] = smb_iconv_open(n2,ln); - if (conv_handles[c1][c2] != (smb_iconv_t)-1) { - continue; - } - } else if (c2==CH_DISPLAY) { - conv_handles[c1][c2] = smb_iconv_open(ln,n1); - if (conv_handles[c1][c2] != (smb_iconv_t)-1) { - continue; - } - } - /* Fall back to the configured charset. */ -#endif conv_handles[c1][c2] = smb_iconv_open(n2,n1); if (conv_handles[c1][c2] == (smb_iconv_t)-1) { DEBUG(0,("Conversion from %s to %s not supported\n", -- cgit From 0a4959d48d62cd97d912182f99e0ea969d48253f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 30 Jun 2003 02:11:13 +0000 Subject: - added LOCALE patch from vorlon@debian.org (Steve Langasek) (bug #122) - changed --enable-developer debug to use -gstabs as it makes the samba binaries about 10x smaller and is still quite functional for samba debugging (This used to be commit 53bfcd478a193d4def8da872e92d7ed8f46aa4b9) --- source3/lib/charcnv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 708ef343e1..55cf73d2b1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -55,6 +55,30 @@ static const char *charset_name(charset_t ch) else if (ch == CH_DISPLAY) ret = lp_display_charset(); else if (ch == CH_UTF8) ret = "UTF8"; +#if defined(HAVE_NL_LANGINFO) && defined(CODESET) + if (ret && strcasecmp(ret, "LOCALE") == 0) { + const char *ln = NULL; + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif + ln = nl_langinfo(CODESET); + if (ln) { + /* Check whether the charset name is supported + by iconv */ + smb_iconv_t handle = smb_iconv_open(ln,"UCS-2LE"); + if (handle == (smb_iconv_t) -1) { + DEBUG(5,("Locale charset '%s' unsupported, using ASCII instead\n", ln)); + ln = NULL; + } else { + DEBUG(5,("Substituting charset '%s' for LOCALE\n", ln)); + smb_iconv_close(handle); + } + } + ret = ln; + } +#endif + if (!ret || !*ret) ret = "ASCII"; return ret; } -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 55cf73d2b1..4e9c2c1592 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -387,7 +387,7 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); - strupper(tmpbuf); + strupper_m(tmpbuf); src = tmpbuf; } @@ -488,7 +488,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); - strupper(tmpbuf); + strupper_m(tmpbuf); src = tmpbuf; } @@ -566,7 +566,7 @@ static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) if (flags & STR_UPPER) { pstrcpy(tmpbuf, src); - strupper(tmpbuf); + strupper_m(tmpbuf); src = tmpbuf; } -- cgit From 77373f1f8e3b2f61e9bbcd9fadfb83257d390cf2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 24 Jul 2003 23:46:27 +0000 Subject: More printf fixes - size_t is long on some architectures. (This used to be commit ba4d334b822248d8ab929c9568533431603d967e) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4e9c2c1592..7910099cd8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -190,7 +190,7 @@ size_t convert_string(charset_t from, charset_t to, break; case E2BIG: reason="No more room"; - DEBUG(0, ("convert_string: Required %d, available %d\n", + DEBUG(0, ("convert_string: Required %l, available %l\n", srclen, destlen)); /* we are not sure we need srclen bytes, may be more, may be less. -- cgit From 7d833de662b83f026b54a236588da27dd8899630 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 25 Jul 2003 04:24:40 +0000 Subject: More printf portability fixes. Got caught out by some gcc'isms last time. )-: (This used to be commit 59dae1da66a5eb7e128263bd578f167d8746e9f0) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7910099cd8..5e1951b6e5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -190,8 +190,8 @@ size_t convert_string(charset_t from, charset_t to, break; case E2BIG: reason="No more room"; - DEBUG(0, ("convert_string: Required %l, available %l\n", - srclen, destlen)); + DEBUG(0, ("convert_string: Required %lu, available %lu\n", + (unsigned long)srclen, (unsigned long)destlen)); /* we are not sure we need srclen bytes, may be more, may be less. We only know we need more than destlen -- cgit From 455bb6de903ca3950d965b29190c09f116d91889 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 27 Jul 2003 02:28:25 +0000 Subject: Some small fixes to our charset conversion code: - Treat the NMB names in the 'session request' packet as 'ASCII'. This means that we do not get invalid multibyte from the wire, even if we truncate in the conversion. (Otherwise we panic when we try to strupper_m it). - Remove acnv_uxu2(), as it was duplicated by push_ucs2_allocate() - Remove acnv_dosu2(), as it is not used. - In push_ucs2(), with the STR_UPPER flag, do the case conversion *after* the UCS2 conversion, when it we know that the length can't change. Also faster, as we don't need to do another 2 UCS2 conversions. Andrew Bartlett (This used to be commit 912035af1178424583d0bf887a391a0cac2acd87) --- source3/lib/charcnv.c | 120 +++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 50 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5e1951b6e5..8896f0b886 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -319,8 +319,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer; - size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, - (void **) &buffer); + size = push_ucs2_allocate(&buffer, src); if (size == -1) { smb_panic("failed to create UCS2 buffer"); } @@ -334,6 +333,35 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) return size; } +/** + strdup() a unix string to upper case. +**/ + +char *strdup_upper(const char *s) +{ + size_t size; + smb_ucs2_t *buffer; + char *out_buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s)+1, + (void **) &buffer); + if (size == -1) { + return NULL; + } + + strupper_w(buffer); + + size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size, + (void **) &out_buffer); + SAFE_FREE(buffer); + + if (size == -1) { + return NULL; + } + + return out_buffer; +} + size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; @@ -353,6 +381,34 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) return size; } +/** + strdup() a unix string to lower case. +**/ + +char *strdup_lower(const char *s) +{ + size_t size; + smb_ucs2_t *buffer; + char *out_buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s), + (void **) &buffer); + if (size == -1) { + return NULL; + } + + strlower_w(buffer); + + size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size, + (void **) &out_buffer); + SAFE_FREE(buffer); + + if (size == -1) { + return NULL; + } + + return out_buffer; +} static size_t ucs2_align(const void *base_ptr, const void *p, int flags) { @@ -480,18 +536,11 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ { size_t len=0; size_t src_len = strlen(src); - pstring tmpbuf; /* treat a pstring as "unlimited" length */ if (dest_len == (size_t)-1) dest_len = sizeof(pstring); - if (flags & STR_UPPER) { - pstrcpy(tmpbuf, src); - strupper_m(tmpbuf); - src = tmpbuf; - } - if (flags & STR_TERMINATE) src_len++; @@ -506,6 +555,18 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ dest_len &= ~1; len += convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len); + + if (flags & STR_UPPER) { + smb_ucs2_t *dest_ucs2 = dest; + size_t i; + for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) { + smb_ucs2_t v = toupper_w(dest_ucs2[i]); + if (v != dest_ucs2[i]) { + dest_ucs2[i] = v; + } + } + } + return len; } @@ -809,44 +870,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags) return 0; } -/** - Convert from unix to ucs2 charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -smb_ucs2_t *acnv_uxu2(const char *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = strlen(src) + 1; - dlen = convert_string_allocate(CH_UNIX, CH_UCS2, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} - -/** - Convert from dos to ucs2 charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -smb_ucs2_t *acnv_dosu2(const char *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = strlen(src) + 1; - dlen = convert_string_allocate(CH_DOS, CH_UCS2, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} -- cgit From 4b3e0268b56042eb72108dbca75ac0bb0aff2514 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 27 Jul 2003 02:40:06 +0000 Subject: Use push_ucs2_allocate(), rather than convert_string_allocate() directly. Remove strdup_upper/strdup_lower from their old file, now that they have been moved to charcnv.c Note that string_replace assumes that s is a pstring. (doco change only) Andrew Bartlett (This used to be commit 6c9056029bb3dfadb244f301598e12e69493fff9) --- source3/lib/charcnv.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 8896f0b886..ca5e378970 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -343,16 +343,14 @@ char *strdup_upper(const char *s) smb_ucs2_t *buffer; char *out_buffer; - size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s)+1, - (void **) &buffer); + size = push_ucs2_allocate(&buffer, s); if (size == -1) { return NULL; } strupper_w(buffer); - size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size, - (void **) &out_buffer); + size = pull_ucs2_allocate(&out_buffer, buffer); SAFE_FREE(buffer); if (size == -1) { @@ -391,16 +389,14 @@ char *strdup_lower(const char *s) smb_ucs2_t *buffer; char *out_buffer; - size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s), - (void **) &buffer); + size = push_ucs2_allocate(&buffer, s); if (size == -1) { return NULL; } strlower_w(buffer); - size = convert_string_allocate(CH_UCS2, CH_UNIX, buffer, size, - (void **) &out_buffer); + size = pull_ucs2_allocate(&out_buffer, buffer); SAFE_FREE(buffer); if (size == -1) { -- cgit From ecddae8bf012c6b9dc4e99c788c14adde64baba8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Aug 2003 22:06:19 +0000 Subject: Attempt to fix the charcnv issues causing nmbd to crash. If we get a failed conversion simply copy as is. Also fixed the horrid malloc-twice-copy code in the convert alloc path. Jeremy. (This used to be commit cfde7477fd12caef943a9422b52174438092a135) --- source3/lib/charcnv.c | 126 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 34 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ca5e378970..2b313d8ccf 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -154,6 +154,9 @@ void init_iconv(void) * @param dest pointer to destination string (multibyte or singlebyte) * @param destlen maximal length allowed for string * @returns the number of bytes occupied in the destination + * + * Ensure the srclen contains the terminating zero. + * **/ size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, @@ -167,16 +170,16 @@ size_t convert_string(charset_t from, charset_t to, if (srclen == (size_t)-1) srclen = strlen(src)+1; + if (srclen == 0) + return 0; lazy_initialize_conv(); descriptor = conv_handles[from][to]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { - /* conversion not supported, use as is */ - size_t len = MIN(srclen,destlen); - memcpy(dest,src,len); - return len; + DEBUG(0,("convert_string: Conversion not supported.\n")); + goto use_as_is; } i_len=srclen; @@ -187,10 +190,11 @@ size_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - break; + DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + goto use_as_is; case E2BIG: reason="No more room"; - DEBUG(0, ("convert_string: Required %lu, available %lu\n", + DEBUG(3, ("convert_string: Required %lu, available %lu\n", (unsigned long)srclen, (unsigned long)destlen)); /* we are not sure we need srclen bytes, may be more, may be less. @@ -198,56 +202,86 @@ size_t convert_string(charset_t from, charset_t to, bytes ---simo */ break; case EILSEQ: - reason="Illegal multibyte sequence"; - break; + reason="Illegal multibyte sequence"; + DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + goto use_as_is; + default: + DEBUG(0,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + break; } /* smb_panic(reason); */ } return destlen-o_len; + + use_as_is: + + /* conversion not supported, use as is */ + { + size_t len = MIN(srclen,destlen); + if (len) + memcpy(dest,src,len); + return len; + } } /** * Convert between character sets, allocating a new buffer for the result. * + * @param ctx TALLOC_CTX to use to allocate with. If NULL use malloc. * @param srclen length of source buffer. * @param dest always set at least to NULL * @note -1 is not accepted for srclen. * * @returns Size in bytes of the converted string; or -1 in case of error. + * + * Ensure the srclen contains the terminating zero. **/ -size_t convert_string_allocate(charset_t from, charset_t to, +size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { - size_t i_len, o_len, destlen; + size_t i_len, o_len, destlen = MAX(srclen, 512); size_t retval; const char *inbuf = (const char *)src; - char *outbuf, *ob; + char *outbuf = NULL, *ob = NULL; smb_iconv_t descriptor; *dest = NULL; if (src == NULL || srclen == (size_t)-1) return (size_t)-1; + if (srclen == 0) + return 0; lazy_initialize_conv(); descriptor = conv_handles[from][to]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { - /* conversion not supported, return -1*/ - DEBUG(3, ("convert_string_allocate: conversion not supported!\n")); - return -1; + DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); + goto use_as_is; } - destlen = MAX(srclen, 512); - outbuf = NULL; convert: - destlen = destlen * 2; - ob = (char *)Realloc(outbuf, destlen); + if ((destlen*2) < destlen) { + /* wrapped ! abort. */ + DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); + if (!ctx) + SAFE_FREE(outbuf); + return (size_t)-1; + } else { + destlen = destlen * 2; + } + + if (ctx) + ob = (char *)talloc_realloc(ctx, ob, destlen); + else + ob = (char *)Realloc(ob, destlen); + if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - SAFE_FREE(outbuf); + if (!ctx) + SAFE_FREE(outbuf); return (size_t)-1; } else { outbuf = ob; @@ -262,12 +296,14 @@ convert: switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - break; + DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); + goto use_as_is; case E2BIG: goto convert; case EILSEQ: reason="Illegal multibyte sequence"; - break; + DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); + goto use_as_is; } DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ @@ -275,14 +311,41 @@ convert: } destlen = destlen - o_len; - *dest = (char *)Realloc(ob,destlen); + if (ctx) + *dest = (char *)talloc_realloc(ctx,ob,destlen); + else + *dest = (char *)Realloc(ob,destlen); if (destlen && !*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); - SAFE_FREE(ob); + if (!ctx) + SAFE_FREE(ob); return (size_t)-1; } return destlen; + + use_as_is: + + /* conversion not supported, use as is */ + { + if (srclen && (destlen != srclen)) { + destlen = srclen; + if (ctx) + ob = (char *)talloc_realloc(ctx, ob, destlen); + else + ob = (char *)Realloc(ob, destlen); + if (!ob) { + DEBUG(0, ("convert_string_allocate: realloc failed!\n")); + if (!ctx) + SAFE_FREE(outbuf); + return (size_t)-1; + } + } + if (srclen && ob) + memcpy(ob,(const char *)src,srclen); + *dest = (char *)ob; + return srclen; + } } @@ -298,17 +361,12 @@ convert: static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { - void *alloced_string; size_t dest_len; - /* FIXME: Ridiculous to allocate two buffers and then copy the string! */ - *dest = NULL; - dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string); + dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest); if (dest_len == (size_t)-1) return (size_t)-1; - *dest = talloc_memdup(ctx, alloced_string, dest_len); - SAFE_FREE(alloced_string); if (*dest == NULL) return (size_t)-1; return dest_len; @@ -365,7 +423,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer; - size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, + size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, (void **) &buffer); if (size == -1) { smb_panic("failed to create UCS2 buffer"); @@ -599,7 +657,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); } /** @@ -667,7 +725,7 @@ size_t push_utf8_allocate(char **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } /** @@ -755,7 +813,7 @@ size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest); } /** @@ -785,7 +843,7 @@ size_t pull_utf8_allocate(void **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest); + return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, dest); } /** -- cgit From a8eda05d75c8d9652a0279a67886e5d6eaf551f3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Aug 2003 23:55:29 +0000 Subject: Shut conversion errors up when initialising tables. Jeremy. (This used to be commit 94d0f888c9abd52e26ef5fc597ade5426a521227) --- source3/lib/charcnv.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2b313d8ccf..02d94582fb 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -40,7 +40,7 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; - +static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */ /** * Return the name of a charset to give to iconv(). @@ -141,8 +141,10 @@ void init_iconv(void) /* XXX: Does this really get called every time the dos * codepage changes? */ /* XXX: Is the did_reload test too strict? */ + conv_silent = True; init_doschar_table(); init_valid_table(); + conv_silent = False; } } @@ -178,7 +180,8 @@ size_t convert_string(charset_t from, charset_t to, descriptor = conv_handles[from][to]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { - DEBUG(0,("convert_string: Conversion not supported.\n")); + if (!conv_silent) + DEBUG(0,("convert_string: Conversion not supported.\n")); goto use_as_is; } @@ -190,12 +193,14 @@ size_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; case E2BIG: reason="No more room"; - DEBUG(3, ("convert_string: Required %lu, available %lu\n", - (unsigned long)srclen, (unsigned long)destlen)); + if (!conv_silent) + DEBUG(3, ("convert_string: Required %lu, available %lu\n", + (unsigned long)srclen, (unsigned long)destlen)); /* we are not sure we need srclen bytes, may be more, may be less. We only know we need more than destlen @@ -203,10 +208,12 @@ size_t convert_string(charset_t from, charset_t to, break; case EILSEQ: reason="Illegal multibyte sequence"; - DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; default: - DEBUG(0,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(0,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); break; } /* smb_panic(reason); */ @@ -258,14 +265,16 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, descriptor = conv_handles[from][to]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { - DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); + if (!conv_silent) + DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); goto use_as_is; } convert: if ((destlen*2) < destlen) { /* wrapped ! abort. */ - DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); + if (!conv_silent) + DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); if (!ctx) SAFE_FREE(outbuf); return (size_t)-1; @@ -296,16 +305,19 @@ convert: switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; case E2BIG: goto convert; case EILSEQ: reason="Illegal multibyte sequence"; - DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; } - DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); + if (!conv_silent) + DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ return (size_t)-1; } -- cgit From dac11b890b3e81f8849340e582b7f397a612baba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 23 Aug 2003 01:59:14 +0000 Subject: Half-way though the big conversion of all nmbd access to wire elements being converted to pull/push_ascii. This will not work right at the moment for non English codepages, but compiles - I will finish the work over the weekend. Then nmbd should be completely codepage correct. Jeremy. (This used to be commit 236d6adadf32397b28028ea82ae2ec027366f7c8) --- source3/lib/charcnv.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 02d94582fb..7f372b358f 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -529,6 +529,11 @@ size_t push_ascii_pstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } +size_t push_ascii_nstring(void *dest, const char *src) +{ + return push_ascii(dest, src, sizeof(nstring), STR_TERMINATE); +} + /** * Copy a string from a dos codepage source to a unix char* destination. * @@ -582,6 +587,11 @@ size_t pull_ascii_fstring(char *dest, const void *src) return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } +size_t pull_ascii_nstring(char *dest, const void *src) +{ + return pull_ascii(dest, src, sizeof(nstring), sizeof(nstring), STR_TERMINATE); +} + /** * Copy a string from a char* src to a unicode destination. * -- cgit From 245fbf7efbc42530c81d5aac66681bb892c97557 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Sep 2003 01:12:39 +0000 Subject: Used cachegrind to track down some bottlenecks. Removed calls to clobber_region when not compiling with developer as they were hiding speed problems. Added fast path to convert_string() when dealing with ascii -> ascii, ucs2-le to ascii and ascii to ucs2-le with values <= 0x7F. This gives a speedup of 22% on my nbench tests. Next I will do this on convert_string_allocate. Jeremy. (This used to be commit ef140d15ea0d76a3e7cdcadbfd3e917c210a9411) --- source3/lib/charcnv.c | 105 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 11 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7f372b358f..53182e13ec 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -150,6 +150,7 @@ void init_iconv(void) /** * Convert string from one encoding to another, making error checking etc + * Slow path version - uses (slow) iconv. * * @param src pointer to source string (multibyte or singlebyte) * @param srclen length of the source string in bytes @@ -160,7 +161,8 @@ void init_iconv(void) * Ensure the srclen contains the terminating zero. * **/ -size_t convert_string(charset_t from, charset_t to, + +static size_t convert_string_internal(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) { @@ -170,18 +172,13 @@ size_t convert_string(charset_t from, charset_t to, char* outbuf = (char*)dest; smb_iconv_t descriptor; - if (srclen == (size_t)-1) - srclen = strlen(src)+1; - if (srclen == 0) - return 0; - lazy_initialize_conv(); descriptor = conv_handles[from][to]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) - DEBUG(0,("convert_string: Conversion not supported.\n")); + DEBUG(0,("convert_string_internal: Conversion not supported.\n")); goto use_as_is; } @@ -194,12 +191,12 @@ size_t convert_string(charset_t from, charset_t to, case EINVAL: reason="Incomplete multibyte sequence"; if (!conv_silent) - DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; case E2BIG: reason="No more room"; if (!conv_silent) - DEBUG(3, ("convert_string: Required %lu, available %lu\n", + DEBUG(3, ("convert_string_internal: Required %lu, available %lu\n", (unsigned long)srclen, (unsigned long)destlen)); /* we are not sure we need srclen bytes, may be more, may be less. @@ -209,11 +206,11 @@ size_t convert_string(charset_t from, charset_t to, case EILSEQ: reason="Illegal multibyte sequence"; if (!conv_silent) - DEBUG(3,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); goto use_as_is; default: if (!conv_silent) - DEBUG(0,("convert_string: Conversion error: %s(%s)\n",reason,inbuf)); + DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); break; } /* smb_panic(reason); */ @@ -231,6 +228,90 @@ size_t convert_string(charset_t from, charset_t to, } } +/** + * Convert string from one encoding to another, making error checking etc + * Fast path version - handles ASCII first. + * + * @param src pointer to source string (multibyte or singlebyte) + * @param srclen length of the source string in bytes + * @param dest pointer to destination string (multibyte or singlebyte) + * @param destlen maximal length allowed for string + * @returns the number of bytes occupied in the destination + * + * Ensure the srclen contains the terminating zero. + * + **/ + +size_t convert_string(charset_t from, charset_t to, + void const *src, size_t srclen, + void *dest, size_t destlen) +{ + if (srclen == (size_t)-1) { + if (from == CH_UCS2) + srclen = strlen_w(src)+2; + else + srclen = strlen(src)+1; + } + if (srclen == 0) + return 0; + + if (from != CH_UCS2 && to != CH_UCS2) { + const unsigned char *p = (const unsigned char *)src; + unsigned char *q = (unsigned char *)dest; + size_t retval = 0; + + /* If all characters are ascii, fast path here. */ + while (srclen && destlen) { + if (*p <= 0x7f) { + *q++ = *p++; + srclen--; + destlen--; + retval++; + } else { + return retval + convert_string_internal(from, to, p, srclen, q, destlen); + } + } + return retval; + } else if (from == CH_UCS2 && to != CH_UCS2) { + const unsigned char *p = (const unsigned char *)src; + unsigned char *q = (unsigned char *)dest; + size_t retval = 0; + + /* If all characters are ascii, fast path here. */ + while ((srclen >= 2) && destlen) { + if (*p <= 0x7f && p[1] == 0) { + *q++ = *p; + srclen -= 2; + p += 2; + destlen--; + retval++; + } else { + return retval + convert_string_internal(from, to, p, srclen, q, destlen); + } + } + return retval; + } else if (from != CH_UCS2 && to == CH_UCS2) { + const unsigned char *p = (const unsigned char *)src; + unsigned char *q = (unsigned char *)dest; + size_t retval = 0; + + /* If all characters are ascii, fast path here. */ + while (srclen && (destlen >= 2)) { + if (*p <= 0x7F) { + *q++ = *p++; + *q++ = '\0'; + srclen--; + destlen -= 2; + retval += 2; + } else { + return retval + convert_string_internal(from, to, p, srclen, q, destlen); + } + } + return retval; + } + return convert_string_internal(from, to, src, srclen, dest, destlen); +} + /** * Convert between character sets, allocating a new buffer for the result. * @@ -925,8 +1006,10 @@ size_t push_string_fn(const char *function, unsigned int line, const void *base_ size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { +#ifdef DEVELOPER if (dest_len != (size_t)-1) clobber_region(function, line, dest, dest_len); +#endif if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ -- cgit From 22831019dcf9dad93256e7104e41bebcbc666c02 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Sep 2003 18:40:55 +0000 Subject: Remove convert_string_internal completely from fast path when processing NBENCH calls. Requires fixed buffer size for strdup_upper(). Jeremy. (This used to be commit e98fbfaf384bd2d3ebb002b0b981366377fb5ac0) --- source3/lib/charcnv.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 53182e13ec..080da8a690 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -258,15 +258,18 @@ size_t convert_string(charset_t from, charset_t to, if (from != CH_UCS2 && to != CH_UCS2) { const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; + unsigned char lastp; size_t retval = 0; /* If all characters are ascii, fast path here. */ while (srclen && destlen) { - if (*p <= 0x7f) { + if ((lastp = *p) <= 0x7f) { *q++ = *p++; srclen--; destlen--; retval++; + if (!lastp) + break; } else { return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -276,15 +279,18 @@ size_t convert_string(charset_t from, charset_t to, const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; + unsigned char lastp; /* If all characters are ascii, fast path here. */ while ((srclen >= 2) && destlen) { - if (*p <= 0x7f && p[1] == 0) { + if ((lastp = *p) <= 0x7f && p[1] == 0) { *q++ = *p; srclen -= 2; p += 2; destlen--; retval++; + if (!lastp) + break; } else { return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -294,15 +300,18 @@ size_t convert_string(charset_t from, charset_t to, const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; + unsigned char lastp; /* If all characters are ascii, fast path here. */ while (srclen && (destlen >= 2)) { - if (*p <= 0x7F) { + if ((lastp = *p) <= 0x7F) { *q++ = *p++; *q++ = '\0'; srclen--; destlen -= 2; retval += 2; + if (!lastp) + break; } else { return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -486,29 +495,28 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) /** strdup() a unix string to upper case. + Max size is pstring. **/ char *strdup_upper(const char *s) { size_t size; - smb_ucs2_t *buffer; - char *out_buffer; + wpstring buffer; + pstring out_buffer; - size = push_ucs2_allocate(&buffer, s); + size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer)); if (size == -1) { return NULL; } strupper_w(buffer); - size = pull_ucs2_allocate(&out_buffer, buffer); - SAFE_FREE(buffer); - + size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer)); if (size == -1) { return NULL; } - return out_buffer; + return strdup(out_buffer); } size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) -- cgit From 0e8c2a4133158b59426ec0b260e97d1dacf98e73 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Sep 2003 23:03:58 +0000 Subject: More hand-tuning of the fastpath. Don't do strlen() when we're doing to walk to the end anyway. Jeremy. (This used to be commit 467cafdb1f7ddfb4278824f385b732975246a4f5) --- source3/lib/charcnv.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 080da8a690..a07ff7399d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -240,18 +240,14 @@ static size_t convert_string_internal(charset_t from, charset_t to, * * Ensure the srclen contains the terminating zero. * + * This function has been hand-tuned to provide a fast path. + * Don't change unless you really know what you are doing. JRA. **/ size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) { - if (srclen == (size_t)-1) { - if (from == CH_UCS2) - srclen = strlen_w(src)+2; - else - srclen = strlen(src)+1; - } if (srclen == 0) return 0; @@ -265,12 +261,17 @@ size_t convert_string(charset_t from, charset_t to, while (srclen && destlen) { if ((lastp = *p) <= 0x7f) { *q++ = *p++; - srclen--; + if (srclen != (size_t)-1) { + srclen--; + } destlen--; retval++; if (!lastp) break; } else { + if (srclen == (size_t)-1) { + srclen = strlen(src)+1; + } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } } @@ -285,13 +286,18 @@ size_t convert_string(charset_t from, charset_t to, while ((srclen >= 2) && destlen) { if ((lastp = *p) <= 0x7f && p[1] == 0) { *q++ = *p; - srclen -= 2; + if (srclen != (size_t)-1) { + srclen -= 2; + } p += 2; destlen--; retval++; if (!lastp) break; } else { + if (srclen == (size_t)-1) { + srclen = strlen_w(src)+2; + } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } } @@ -307,12 +313,17 @@ size_t convert_string(charset_t from, charset_t to, if ((lastp = *p) <= 0x7F) { *q++ = *p++; *q++ = '\0'; - srclen--; + if (srclen != (size_t)-1) { + srclen--; + } destlen -= 2; retval += 2; if (!lastp) break; } else { + if (srclen == (size_t)-1) { + srclen = strlen(src)+1; + } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } } @@ -697,22 +708,26 @@ size_t pull_ascii_nstring(char *dest, const void *src) * @param dest_len is the maximum length allowed in the * destination. If dest_len is -1 then no maxiumum is used. **/ + size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; - size_t src_len = strlen(src); + size_t src_len; /* treat a pstring as "unlimited" length */ if (dest_len == (size_t)-1) dest_len = sizeof(pstring); if (flags & STR_TERMINATE) - src_len++; + src_len = (size_t)-1; + else + src_len = strlen(src); if (ucs2_align(base_ptr, dest, flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); - if (dest_len) dest_len--; + if (dest_len) + dest_len--; len++; } -- cgit From 94f59f54921174fc156fade575ca114d331b1bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2003 19:59:55 +0000 Subject: More tuning from cachegrind. Change most trim_string() calls to trim_char(0, as that's what they do. Fix string_replace() to fast-path ascii. Jeremy. (This used to be commit f35e9a8b909d3c74be47083ccc4a4e91a14938db) --- source3/lib/charcnv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a07ff7399d..ceb9d57fc7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -879,9 +879,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ } if (flags & STR_TERMINATE) { - if (src_len == (size_t)-1) { - src_len = strlen_w(src)*2 + 2; - } else { + /* src_len -1 is the default for null terminated strings. */ + if (src_len != (size_t)-1) { size_t len = strnlen_w(src, src_len/2); if (len < src_len/2) len++; @@ -1051,4 +1050,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags) } return 0; } - -- cgit From 966b0fc7c96b1dba63fa755312a2be64e18ff471 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2003 21:30:50 +0000 Subject: More cachegrind tuning, plus fix an error message. Jeremy. (This used to be commit 8cb9ec5d533085d40fc6bfe4ca9647d80bf41ac7) --- source3/lib/charcnv.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ceb9d57fc7..5a922e226c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -511,22 +511,43 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_upper(const char *s) { - size_t size; - wpstring buffer; pstring out_buffer; - - size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer)); - if (size == -1) { - return NULL; + const unsigned char *p = (const unsigned char *)s; + unsigned char *q = (unsigned char *)out_buffer; + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + + while (1) { + if (*p & 0x80) + break; + *q++ = toupper(*p); + if (!*p) + break; + p++; + if (p - ( const unsigned char *)s >= sizeof(pstring)) + break; } - strupper_w(buffer); + if (*p) { + /* MB case. */ + size_t size; + wpstring buffer; + size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer)); + if (size == -1) { + return NULL; + } + + strupper_w(buffer); - size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer)); - if (size == -1) { - return NULL; + size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer)); + if (size == -1) { + return NULL; + } } - + return strdup(out_buffer); } -- cgit From 16e6d22408cd00852bc1a796815e77820d0df788 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 8 Sep 2003 21:26:30 +0000 Subject: Fix valgrind-found read of uninit variable (ensure length is right). Jeremy. (This used to be commit 6fc0e529f70253244628017a372257e8dc053294) --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5a922e226c..5f3cf64a68 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -270,7 +270,7 @@ size_t convert_string(charset_t from, charset_t to, break; } else { if (srclen == (size_t)-1) { - srclen = strlen(src)+1; + srclen = strlen(p)+1; } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -296,7 +296,7 @@ size_t convert_string(charset_t from, charset_t to, break; } else { if (srclen == (size_t)-1) { - srclen = strlen_w(src)+2; + srclen = strlen_w((const void *)p)+2; } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -322,7 +322,7 @@ size_t convert_string(charset_t from, charset_t to, break; } else { if (srclen == (size_t)-1) { - srclen = strlen(src)+1; + srclen = strlen(p)+1; } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } -- cgit From ee51d6aabe9398a9b4a3bf99d8b6f3c23cdc075c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 10 Sep 2003 02:21:24 +0000 Subject: Fix mb bug in fast path code. strlen_w() returns number of *characters* not number of bytes. Reproduce this by trying to rename the file named : sibréseau -> sibréseaU from Windows 2000 explorer. Jeremy. (This used to be commit 035f59599514491609078ac0fe5804278c43a9b3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5f3cf64a68..e8ae40dbe2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -284,7 +284,7 @@ size_t convert_string(charset_t from, charset_t to, /* If all characters are ascii, fast path here. */ while ((srclen >= 2) && destlen) { - if ((lastp = *p) <= 0x7f && p[1] == 0) { + if (((lastp = *p) <= 0x7f) && (p[1] == 0)) { *q++ = *p; if (srclen != (size_t)-1) { srclen -= 2; @@ -296,7 +296,7 @@ size_t convert_string(charset_t from, charset_t to, break; } else { if (srclen == (size_t)-1) { - srclen = strlen_w((const void *)p)+2; + srclen = (strlen_w((const smb_ucs2_t *)p)+1) * 2; } return retval + convert_string_internal(from, to, p, srclen, q, destlen); } @@ -542,7 +542,7 @@ char *strdup_upper(const char *s) strupper_w(buffer); - size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer)); + size = convert_string(CH_UCS2, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer)); if (size == -1) { return NULL; } -- cgit From cba653c30a0ed2382b7d252b5dc82a28247372b3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Sep 2003 22:41:21 +0000 Subject: Fix for MacOS/X which uses STUPID BROKEN UNICODE COMPOSE CHARACTERS ! (rant off :-). Inspired by work from Benjamin Riefenstahl . Also add MacOSX/Darwin configure fixes. Jerry - can we put this in 3.0 release ? :-). Jeremy. (This used to be commit f23acb4ca5feac8ad2acfa1baf7df31283aba3ea) --- source3/lib/charcnv.c | 75 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 24 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index e8ae40dbe2..dafc88fb77 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -176,6 +176,14 @@ static size_t convert_string_internal(charset_t from, charset_t to, descriptor = conv_handles[from][to]; + if (srclen == (size_t)-1) { + if (from == CH_UCS2) { + srclen = (strlen_w((const smb_ucs2_t *)src)+1) * 2; + } else { + srclen = strlen((const char *)src)+1; + } + } + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_internal: Conversion not supported.\n")); @@ -248,31 +256,40 @@ size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen) { + /* + * NB. We deliberately don't do a strlen here is srclen == -1. + * This is very expensive over millions of calls and is taken + * care of in the slow path in convert_string_internal. JRA. + */ + if (srclen == 0) return 0; if (from != CH_UCS2 && to != CH_UCS2) { const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; + size_t slen = srclen; + size_t dlen = destlen; unsigned char lastp; size_t retval = 0; /* If all characters are ascii, fast path here. */ - while (srclen && destlen) { + while (slen && dlen) { if ((lastp = *p) <= 0x7f) { *q++ = *p++; - if (srclen != (size_t)-1) { - srclen--; + if (slen != (size_t)-1) { + slen--; } - destlen--; + dlen--; retval++; if (!lastp) break; } else { - if (srclen == (size_t)-1) { - srclen = strlen(p)+1; - } - return retval + convert_string_internal(from, to, p, srclen, q, destlen); +#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS + goto general_case; +#else + return retval + convert_string_internal(from, to, p, slen, q, dlen); +#endif } } return retval; @@ -280,25 +297,28 @@ size_t convert_string(charset_t from, charset_t to, const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; + size_t slen = srclen; + size_t dlen = destlen; unsigned char lastp; /* If all characters are ascii, fast path here. */ - while ((srclen >= 2) && destlen) { + while ((slen >= 2) && dlen) { if (((lastp = *p) <= 0x7f) && (p[1] == 0)) { *q++ = *p; - if (srclen != (size_t)-1) { - srclen -= 2; + if (slen != (size_t)-1) { + slen -= 2; } p += 2; - destlen--; + dlen--; retval++; if (!lastp) break; } else { - if (srclen == (size_t)-1) { - srclen = (strlen_w((const smb_ucs2_t *)p)+1) * 2; - } - return retval + convert_string_internal(from, to, p, srclen, q, destlen); +#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS + goto general_case; +#else + return retval + convert_string_internal(from, to, p, slen, q, dlen); +#endif } } return retval; @@ -306,29 +326,36 @@ size_t convert_string(charset_t from, charset_t to, const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; + size_t slen = srclen; + size_t dlen = destlen; unsigned char lastp; /* If all characters are ascii, fast path here. */ - while (srclen && (destlen >= 2)) { + while (slen && (dlen >= 2)) { if ((lastp = *p) <= 0x7F) { *q++ = *p++; *q++ = '\0'; - if (srclen != (size_t)-1) { - srclen--; + if (slen != (size_t)-1) { + slen--; } - destlen -= 2; + dlen -= 2; retval += 2; if (!lastp) break; } else { - if (srclen == (size_t)-1) { - srclen = strlen(p)+1; - } - return retval + convert_string_internal(from, to, p, srclen, q, destlen); +#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS + goto general_case; +#else + return retval + convert_string_internal(from, to, p, slen, q, dlen); +#endif } } return retval; } + +#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS + general_case: +#endif return convert_string_internal(from, to, src, srclen, dest, destlen); } -- 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/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index dafc88fb77..9d15c6daa0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -56,7 +56,7 @@ static const char *charset_name(charset_t ch) else if (ch == CH_UTF8) ret = "UTF8"; #if defined(HAVE_NL_LANGINFO) && defined(CODESET) - if (ret && strcasecmp(ret, "LOCALE") == 0) { + if (ret && !strcmp(ret, "LOCALE")) { const char *ln = NULL; #ifdef HAVE_SETLOCALE -- cgit From e6994778ec082fab422051028ddbdd81b9ae0275 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 13 Nov 2003 17:27:21 +0000 Subject: Fix a couple of warnings with casts. (This used to be commit 58d7a51c5762a444aae6a795a3703269134423d7) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9d15c6daa0..0a6a1fc75d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -192,7 +192,7 @@ static size_t convert_string_internal(charset_t from, charset_t to, i_len=srclen; o_len=destlen; - retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); + retval = smb_iconv(descriptor, (char **)&inbuf, &i_len, &outbuf, &o_len); if(retval==(size_t)-1) { const char *reason="unknown error"; switch(errno) { @@ -426,7 +426,7 @@ convert: i_len = srclen; o_len = destlen; retval = smb_iconv(descriptor, - &inbuf, &i_len, + (char **)&inbuf, &i_len, &outbuf, &o_len); if(retval == (size_t)-1) { const char *reason="unknown error"; -- cgit From c4167baca1f8890a1fccce2273f1809def3d9703 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 Dec 2003 22:46:46 +0000 Subject: Get a little paranoid about memfree use in convert_string_allocate.. Looking at crash bugs #809 and others. Jeremy. (This used to be commit cd2075580b0f35c8a414c995f03834c01efaa9be) --- source3/lib/charcnv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0a6a1fc75d..6a00402193 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -488,7 +488,6 @@ convert: } } - /** * Convert between character sets, allocating a new buffer using talloc for the result. * @@ -581,19 +580,19 @@ char *strdup_upper(const char *s) size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer; + smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, (void **) &buffer); - if (size == -1) { + if (size == -1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { - free(buffer); + SAFE_FREE(buffer); return srclen; } size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); - free(buffer); + SAFE_FREE(buffer); return size; } @@ -604,11 +603,11 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_lower(const char *s) { size_t size; - smb_ucs2_t *buffer; + smb_ucs2_t *buffer = NULL; char *out_buffer; size = push_ucs2_allocate(&buffer, s); - if (size == -1) { + if (size == -1 || !buffer) { return NULL; } -- cgit From 5eee23cc64139ba1d23101c87709e6d5198a6c68 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 31 Dec 2003 00:31:43 +0000 Subject: auth/auth_util.c: - Fill in the 'backup' idea of a domain, if the DC didn't supply one. This doesn't seem to occour in reality, hence why we missed the typo. lib/charcnv.c: lib/smbldap.c: libads/ldap.c: libsmb/libsmbclient.c: printing/nt_printing.c: - all the callers to pull_utf8_allocate() pass a char ** as the first parammeter, so don't make them all cast it to a void ** nsswitch/winbind_util.c: - Allow for a more 'correct' view of when usernames should be qualified in winbindd. If we are a PDC, or have 'winbind trusted domains only', then for the authentication returns stip the domain portion. - Fix valgrind warning about use of free()ed name when looking up our local domain. lp_workgroup() is maniplated inside a procedure that uses it's former value. Instead, use the fact that our local domain is always the first in the list. Andrew Bartlett (This used to be commit 494781f628683d6e68e8ba21ae54f738727e8c21) --- source3/lib/charcnv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6a00402193..1c6058a43e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1011,11 +1011,11 @@ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) * @returns The number of bytes occupied by the string in the destination **/ -size_t pull_utf8_allocate(void **dest, const char *src) +size_t pull_utf8_allocate(char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, dest); + return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); } /** -- cgit From b20f1a95a90033f711a26fdeeb49eaf3059ad91d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 15 Jan 2004 19:03:18 +0000 Subject: * BUG 446 - setup_logging() in smbclient to be interactive (remove the timestamps) - Fix bad return value in pull_ucs2( needs more testing to make sure this didn't break something else) that caused clistr_pull() to always read the same string from the buffer (pull_usc2() could return -1 if the original source length was given as -1) - increment some debugging messages to avoid printing them out so often (This used to be commit 79fe75dcdf6cc38e18ca1231e4357893db4d4a08) --- source3/lib/charcnv.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 1c6058a43e..5f9392b620 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -940,6 +940,10 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ src_len &= ~1; ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); + + if (src_len == (size_t)-1) + src_len = ret*2; + if (dest_len) dest[MIN(ret, dest_len-1)] = 0; else -- cgit From 423ad9097448e5a07ba26172302450ae7165d85a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Feb 2004 12:02:43 +0000 Subject: the conversion from int to size_t in charcnv did not take into account one place where we checked "if (src_len > 0)". I actually would greatly prefer to switch back to int for src_len. The type *can* be negative, which means an unsigned type is inappropriate. There is absolutely no reason why "int" should not be used for a parameter like this. I didn't change back to int as we are close to a release and I wanted a mininal change, but please don't go changing types like this in future without very careful testing and a damn good reason. this bug broke pull_ucs2(), I would not be surprised if it caused all sorts of nastiness. Thanks to vl for noticing the symptoms! (This used to be commit 8b8f0c527959c707f274b435fc59156e37232981) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5f9392b620..aed1b79a8e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -921,7 +921,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (ucs2_align(base_ptr, src, flags)) { src = (const void *)((const char *)src + 1); - if (src_len > 0) + if (src_len != (size_t)-1) src_len--; } -- 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/charcnv.c | 92 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 10 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index aed1b79a8e..cda26bed6d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -184,14 +184,18 @@ static size_t convert_string_internal(charset_t from, charset_t to, } } + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_internal: Conversion not supported.\n")); - goto use_as_is; + return 0; } i_len=srclen; o_len=destlen; + + again: + retval = smb_iconv(descriptor, (char **)&inbuf, &i_len, &outbuf, &o_len); if(retval==(size_t)-1) { const char *reason="unknown error"; @@ -227,12 +231,76 @@ static size_t convert_string_internal(charset_t from, charset_t to, use_as_is: - /* conversion not supported, use as is */ + /* + * Conversion not supported. This is actually an error, but there are so + * many misconfigured iconv systems and smb.conf's out there we can't just + * fail. Do a very bad conversion instead.... JRA. + */ + { - size_t len = MIN(srclen,destlen); - if (len) - memcpy(dest,src,len); - return len; + if (o_len == 0 || i_len == 0) + return destlen - o_len; + + if (from == CH_UCS2 && to != CH_UCS2) { + /* Can't convert from ucs2 to multibyte. Just truncate this char to ascii. */ + if (i_len < 2) + return destlen - o_len; + if (i_len >= 2) { + *outbuf = inbuf[0]; + + outbuf++; + o_len--; + + inbuf += 2; + i_len -= 2; + } + + if (o_len == 0 || i_len == 0) + return destlen - o_len; + + /* Keep trying with the next char... */ + goto again; + + } else if (from != CH_UCS2 && to == CH_UCS2) { + /* Can't convert to ucs2 - just widen by adding zero. */ + if (o_len < 2) + return destlen; + outbuf[0] = inbuf[0]; + outbuf[1] = '\0'; + + inbuf++; + i_len--; + + outbuf += 2; + o_len -= 2; + + if (o_len == 0 || i_len == 0) + return destlen - o_len; + + /* Keep trying with the next char... */ + goto again; + + } else if (from != CH_UCS2 && to != CH_UCS2) { + /* Failed multibyte to multibyte. Just copy 1 char and + try again. */ + outbuf[0] = inbuf[0]; + + inbuf++; + i_len--; + + outbuf++; + o_len--; + + if (o_len == 0 || i_len == 0) + return destlen - o_len; + + /* Keep trying with the next char... */ + goto again; + + } else { + /* Keep compiler happy.... */ + return destlen - o_len; + } } } @@ -241,9 +309,9 @@ static size_t convert_string_internal(charset_t from, charset_t to, * Fast path version - handles ASCII first. * * @param src pointer to source string (multibyte or singlebyte) - * @param srclen length of the source string in bytes + * @param srclen length of the source string in bytes, or -1 for nul terminated. * @param dest pointer to destination string (multibyte or singlebyte) - * @param destlen maximal length allowed for string + * @param destlen maximal length allowed for string - *NEVER* -1. * @returns the number of bytes occupied in the destination * * Ensure the srclen contains the terminating zero. @@ -257,11 +325,15 @@ size_t convert_string(charset_t from, charset_t to, void *dest, size_t destlen) { /* - * NB. We deliberately don't do a strlen here is srclen == -1. + * NB. We deliberately don't do a strlen here if srclen == -1. * This is very expensive over millions of calls and is taken * care of in the slow path in convert_string_internal. JRA. */ +#ifdef DEVELOPER + SMB_ASSERT(destlen != (size_t)-1); +#endif + if (srclen == 0) return 0; @@ -302,7 +374,7 @@ size_t convert_string(charset_t from, charset_t to, unsigned char lastp; /* If all characters are ascii, fast path here. */ - while ((slen >= 2) && dlen) { + while (((slen == (size_t)-1) || (slen >= 2)) && dlen) { if (((lastp = *p) <= 0x7f) && (p[1] == 0)) { *q++ = *p; if (slen != (size_t)-1) { -- cgit From ef743c06415a4d33b8fc00ab6dfa8935024d26be Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Feb 2004 19:13:45 +0000 Subject: Fixup the allocate version of the function to do "crap" conversions too. Embarrassing number of goto's in this :-(. Fixes #830 I think. Jeremy. (This used to be commit 4c182d3220e87ea74d9c977b8ab1d740ef4cc30f) --- source3/lib/charcnv.c | 103 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 20 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cda26bed6d..9db05d8e16 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -264,7 +264,8 @@ static size_t convert_string_internal(charset_t from, charset_t to, } else if (from != CH_UCS2 && to == CH_UCS2) { /* Can't convert to ucs2 - just widen by adding zero. */ if (o_len < 2) - return destlen; + return destlen - o_len; + outbuf[0] = inbuf[0]; outbuf[1] = '\0'; @@ -442,6 +443,9 @@ size_t convert_string(charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. * * Ensure the srclen contains the terminating zero. + * + * I hate the goto's in this function. It's embarressing..... + * There has to be a cleaner way to do this. JRA. **/ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, @@ -470,7 +474,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, goto use_as_is; } -convert: + convert: + if ((destlen*2) < destlen) { /* wrapped ! abort. */ if (!conv_silent) @@ -497,6 +502,9 @@ convert: } i_len = srclen; o_len = destlen; + + again: + retval = smb_iconv(descriptor, (char **)&inbuf, &i_len, &outbuf, &o_len); @@ -521,7 +529,9 @@ convert: /* smb_panic(reason); */ return (size_t)-1; } - + + out: + destlen = destlen - o_len; if (ctx) *dest = (char *)talloc_realloc(ctx,ob,destlen); @@ -536,27 +546,80 @@ convert: return destlen; - use_as_is: + use_as_is: + + /* + * Conversion not supported. This is actually an error, but there are so + * many misconfigured iconv systems and smb.conf's out there we can't just + * fail. Do a very bad conversion instead.... JRA. + */ - /* conversion not supported, use as is */ { - if (srclen && (destlen != srclen)) { - destlen = srclen; - if (ctx) - ob = (char *)talloc_realloc(ctx, ob, destlen); - else - ob = (char *)Realloc(ob, destlen); - if (!ob) { - DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - if (!ctx) - SAFE_FREE(outbuf); - return (size_t)-1; + if (o_len == 0 || i_len == 0) + goto out; + + if (from == CH_UCS2 && to != CH_UCS2) { + /* Can't convert from ucs2 to multibyte. Just truncate this char to ascii. */ + if (i_len < 2) + goto out; + + if (i_len >= 2) { + *outbuf = inbuf[0]; + + outbuf++; + o_len--; + + inbuf += 2; + i_len -= 2; } + + if (o_len == 0 || i_len == 0) + goto out; + + /* Keep trying with the next char... */ + goto again; + + } else if (from != CH_UCS2 && to == CH_UCS2) { + /* Can't convert to ucs2 - just widen by adding zero. */ + if (o_len < 2) + goto out; + + outbuf[0] = inbuf[0]; + outbuf[1] = '\0'; + + inbuf++; + i_len--; + + outbuf += 2; + o_len -= 2; + + if (o_len == 0 || i_len == 0) + goto out; + + /* Keep trying with the next char... */ + goto again; + + } else if (from != CH_UCS2 && to != CH_UCS2) { + /* Failed multibyte to multibyte. Just copy 1 char and + try again. */ + outbuf[0] = inbuf[0]; + + inbuf++; + i_len--; + + outbuf++; + o_len--; + + if (o_len == 0 || i_len == 0) + goto out; + + /* Keep trying with the next char... */ + goto again; + + } else { + /* Keep compiler happy.... */ + goto out; } - if (srclen && ob) - memcpy(ob,(const char *)src,srclen); - *dest = (char *)ob; - return srclen; } } -- cgit From e3f5b542707e2328030b9d5eff0836a904eccde5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Mar 2004 22:48:24 +0000 Subject: Restore the contract on all convert_stringXX() interfaces. Add a "allow_bad_conv" boolean parameter that allows broken iconv conversions to work. Gets rid of the nasty errno checks in mangle_hash2 and check_path_syntax and allows correct return code checking. Jeremy. (This used to be commit 7b96765c23637613f079d37566d95d5edd511f05) --- source3/lib/charcnv.c | 102 +++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 39 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9db05d8e16..cab81fccc5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -156,6 +156,7 @@ void init_iconv(void) * @param srclen length of the source string in bytes * @param dest pointer to destination string (multibyte or singlebyte) * @param destlen maximal length allowed for string + * @param allow_bad_conv determines if a "best effort" conversion is acceptable (never returns errors) * @returns the number of bytes occupied in the destination * * Ensure the srclen contains the terminating zero. @@ -164,7 +165,7 @@ void init_iconv(void) static size_t convert_string_internal(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen) + void *dest, size_t destlen, BOOL allow_bad_conv) { size_t i_len, o_len; size_t retval; @@ -188,7 +189,7 @@ static size_t convert_string_internal(charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_internal: Conversion not supported.\n")); - return 0; + return (size_t)-1; } i_len=srclen; @@ -204,7 +205,9 @@ static size_t convert_string_internal(charset_t from, charset_t to, reason="Incomplete multibyte sequence"; if (!conv_silent) DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); - goto use_as_is; + if (allow_bad_conv) + goto use_as_is; + break; case E2BIG: reason="No more room"; if (!conv_silent) @@ -219,7 +222,9 @@ static size_t convert_string_internal(charset_t from, charset_t to, reason="Illegal multibyte sequence"; if (!conv_silent) DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); - goto use_as_is; + if (allow_bad_conv) + goto use_as_is; + break; default: if (!conv_silent) DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf)); @@ -313,6 +318,7 @@ static size_t convert_string_internal(charset_t from, charset_t to, * @param srclen length of the source string in bytes, or -1 for nul terminated. * @param dest pointer to destination string (multibyte or singlebyte) * @param destlen maximal length allowed for string - *NEVER* -1. + * @param allow_bad_conv determines if a "best effort" conversion is acceptable (never returns errors) * @returns the number of bytes occupied in the destination * * Ensure the srclen contains the terminating zero. @@ -323,7 +329,7 @@ static size_t convert_string_internal(charset_t from, charset_t to, size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen) + void *dest, size_t destlen, BOOL allow_bad_conv) { /* * NB. We deliberately don't do a strlen here if srclen == -1. @@ -361,7 +367,7 @@ size_t convert_string(charset_t from, charset_t to, #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS goto general_case; #else - return retval + convert_string_internal(from, to, p, slen, q, dlen); + return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv); #endif } } @@ -390,7 +396,7 @@ size_t convert_string(charset_t from, charset_t to, #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS goto general_case; #else - return retval + convert_string_internal(from, to, p, slen, q, dlen); + return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv); #endif } } @@ -419,7 +425,7 @@ size_t convert_string(charset_t from, charset_t to, #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS goto general_case; #else - return retval + convert_string_internal(from, to, p, slen, q, dlen); + return retval + convert_string_internal(from, to, p, slen, q, dlen, allow_bad_conv); #endif } } @@ -429,7 +435,7 @@ size_t convert_string(charset_t from, charset_t to, #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS general_case: #endif - return convert_string_internal(from, to, src, srclen, dest, destlen); + return convert_string_internal(from, to, src, srclen, dest, destlen, allow_bad_conv); } /** @@ -449,7 +455,7 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest) + void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) { size_t i_len, o_len, destlen = MAX(srclen, 512); size_t retval; @@ -471,7 +477,9 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); - goto use_as_is; + if (allow_bad_conv) + goto use_as_is; + return (size_t)-1; } convert: @@ -515,14 +523,18 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, reason="Incomplete multibyte sequence"; if (!conv_silent) DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); - goto use_as_is; + if (allow_bad_conv) + goto use_as_is; + break; case E2BIG: goto convert; case EILSEQ: reason="Illegal multibyte sequence"; if (!conv_silent) DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf)); - goto use_as_is; + if (allow_bad_conv) + goto use_as_is; + break; } if (!conv_silent) DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); @@ -633,12 +645,12 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. **/ static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest) + void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) { size_t dest_len; *dest = NULL; - dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest); + dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest, allow_bad_conv); if (dest_len == (size_t)-1) return (size_t)-1; if (*dest == NULL) @@ -652,7 +664,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer; size = push_ucs2_allocate(&buffer, src); - if (size == -1) { + if (size == (size_t)-1) { smb_panic("failed to create UCS2 buffer"); } if (!strupper_w(buffer) && (dest == src)) { @@ -660,7 +672,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) return srclen; } - size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True); free(buffer); return size; } @@ -696,15 +708,15 @@ char *strdup_upper(const char *s) /* MB case. */ size_t size; wpstring buffer; - size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer)); - if (size == -1) { + size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer), True); + if (size == (size_t)-1) { return NULL; } strupper_w(buffer); - size = convert_string(CH_UCS2, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer)); - if (size == -1) { + size = convert_string(CH_UCS2, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); + if (size == (size_t)-1) { return NULL; } } @@ -718,15 +730,15 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, - (void **) &buffer); - if (size == -1 || !buffer) { + (void **) &buffer, True); + if (size == (size_t)-1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { SAFE_FREE(buffer); return srclen; } - size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True); SAFE_FREE(buffer); return size; } @@ -751,7 +763,7 @@ char *strdup_lower(const char *s) size = pull_ucs2_allocate(&out_buffer, buffer); SAFE_FREE(buffer); - if (size == -1) { + if (size == (size_t)-1) { return NULL; } @@ -798,7 +810,7 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) src_len++; - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); + return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); } size_t push_ascii_fstring(void *dest, const char *src) @@ -849,7 +861,10 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, } } - ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); + ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True); + if (ret == (size_t)-1) { + dest_len = 0; + } if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -895,6 +910,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ { size_t len=0; size_t src_len; + size_t ret; /* treat a pstring as "unlimited" length */ if (dest_len == (size_t)-1) @@ -916,7 +932,12 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; - len += convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len); + ret = convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len, True); + if (ret == (size_t)-1) { + return 0; + } + + len += ret; if (flags & STR_UPPER) { smb_ucs2_t *dest_ucs2 = dest; @@ -947,7 +968,7 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True); } @@ -965,7 +986,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True); } /** @@ -996,7 +1017,7 @@ static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) if (flags & STR_TERMINATE) src_len++; - return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len); + return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len, True); } size_t push_utf8_fstring(void *dest, const char *src) @@ -1017,7 +1038,7 @@ size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True); } /** @@ -1033,7 +1054,7 @@ size_t push_utf8_allocate(char **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, True); } /** @@ -1074,8 +1095,11 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (src_len != (size_t)-1) src_len &= ~1; - ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len); - + ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len, True); + if (ret == (size_t)-1) { + return 0; + } + if (src_len == (size_t)-1) src_len = ret*2; @@ -1109,7 +1133,7 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True); } /** @@ -1124,7 +1148,7 @@ size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True); } /** @@ -1139,7 +1163,7 @@ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); } /** @@ -1154,7 +1178,7 @@ size_t pull_utf8_allocate(char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); + return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); } /** -- cgit From fd2d4f87d440f24df0adc4cc29f22051536b0dee Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Mar 2004 00:28:53 +0000 Subject: First part of patch from moriyama@miraclelinux.com (MORIYAMA Masayuki) to fix up netbios names with mb strings. Includes reformat of libsmb/nmblib.c so it's readable. Jeremy. (This used to be commit 966e49a48c352563cdd7f75fe2768f2d6612ec7e) --- source3/lib/charcnv.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cab81fccc5..38bb239a12 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -823,9 +823,37 @@ size_t push_ascii_pstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } +/******************************************************************** + Push an nstring - ensure null terminated. Written by + moriyama@miraclelinux.com (MORIYAMA Masayuki). +********************************************************************/ + size_t push_ascii_nstring(void *dest, const char *src) { - return push_ascii(dest, src, sizeof(nstring), STR_TERMINATE); + size_t i, buffer_len, dest_len; + smb_ucs2_t *buffer; + + buffer_len = push_ucs2_allocate(&buffer, src); + if (buffer_len == (size_t)-1) { + smb_panic("failed to create UCS2 buffer"); + } + + dest_len = 0; + for (i = 0; i < buffer_len; i++) { + unsigned char mb[10]; + /* Convert one smb_ucs2_t character at a time. */ + size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False); + if ((mb_len != (size_t)-1) && (dest_len + mb_len <= MAX_NETBIOSNAME_LEN - 1)) { + memcpy((char *)dest + dest_len, mb, mb_len); + dest_len += mb_len; + } else { + break; + } + } + ((char *)dest)[dest_len] = '\0'; + + SAFE_FREE(buffer); + return dest_len; } /** -- cgit From 6b9dbbcd249360fb9acd61d6900baccf621c9cce Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Mar 2004 02:16:21 +0000 Subject: Modified fix for bugid #784. Based on a patch from moriyama@miraclelinux.com (MORIYAMA Masayuki). Don't use nstrings to hold workgroup and netbios names. The problem with them is that MB netbios and workgroup names in unix charset (particularly utf8) may be up to 3x bigger than the name when represented in dos charset (ie. cp932). So go back to using fstrings for these but translate into nstrings (ie. 16 byte length values) for transport on the wire. Jeremy. (This used to be commit b4ea493599ab414f7828b83f40a5a8b43479ff64) --- source3/lib/charcnv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 38bb239a12..28ecf761d3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -839,7 +839,7 @@ size_t push_ascii_nstring(void *dest, const char *src) } dest_len = 0; - for (i = 0; i < buffer_len; i++) { + for (i = 0; buffer[i] != 0 && (i < buffer_len); i++) { unsigned char mb[10]; /* Convert one smb_ucs2_t character at a time. */ size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False); @@ -847,6 +847,7 @@ size_t push_ascii_nstring(void *dest, const char *src) memcpy((char *)dest + dest_len, mb, mb_len); dest_len += mb_len; } else { + errno = E2BIG; break; } } @@ -912,9 +913,11 @@ size_t pull_ascii_fstring(char *dest, const void *src) return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } -size_t pull_ascii_nstring(char *dest, const void *src) +/* When pulling an nstring it can expand into a larger size (dos cp -> utf8). Cope with this. */ + +size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src) { - return pull_ascii(dest, src, sizeof(nstring), sizeof(nstring), STR_TERMINATE); + return pull_ascii(dest, src, dest_len, sizeof(nstring), STR_TERMINATE); } /** -- cgit From a0034d3586dadfddc18e4a3096564bf158d43e4e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Mar 2004 02:47:21 +0000 Subject: Ensure we don't truncate strcmps to nstring anymore... Jeremy. (This used to be commit d7cf64b1e4e501bcd01ddc8279babc65d894a4b3) --- source3/lib/charcnv.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 28ecf761d3..20af806d90 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -833,6 +833,7 @@ size_t push_ascii_nstring(void *dest, const char *src) size_t i, buffer_len, dest_len; smb_ucs2_t *buffer; + conv_silent = True; buffer_len = push_ucs2_allocate(&buffer, src); if (buffer_len == (size_t)-1) { smb_panic("failed to create UCS2 buffer"); @@ -854,6 +855,7 @@ size_t push_ascii_nstring(void *dest, const char *src) ((char *)dest)[dest_len] = '\0'; SAFE_FREE(buffer); + conv_silent = False; return dest_len; } -- cgit From e2fd98af575a5c240593f21df442eb035f35e892 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Tue, 16 Mar 2004 17:18:57 +0000 Subject: Fix check_path_syntax() for multibyte encodings which have no '\' as second byte. This is intermediate fix as discussed with Jeremy until we move check_path_syntax() to UCS2 internally where all ambiguity is resolved. Please add other encodings into charcnv.c with such property.' ' (This used to be commit 2c404f6ba988d68c6f44df9409c0de319553de10) --- source3/lib/charcnv.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 20af806d90..b06d869bcc 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -41,6 +41,15 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */ +/* Unsafe unix charsets which could contain '\\' as second byte of mb character */ +static const char *conv_unsafe_charsets[] = { + "CP932", + "EUC-JP", + NULL}; +/* Global variable which is set to True in init_iconv() if unix charset is unsafe + w.r.t. '\\' in second byte of mb character. Otherwise it is set to False. +*/ +BOOL is_unix_charset_unsafe; /** * Return the name of a charset to give to iconv(). @@ -105,6 +114,7 @@ void init_iconv(void) { int c1, c2; BOOL did_reload = False; + const char **unsafe_charset = conv_unsafe_charsets; /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ @@ -146,6 +156,16 @@ void init_iconv(void) init_valid_table(); conv_silent = False; } + + while(*unsafe_charset && strcmp(*unsafe_charset, conv_handles[CH_UCS2][CH_UNIX]->to_name)) { + unsafe_charset++; + } + + if (*unsafe_charset) { + is_unix_charset_unsafe = True; + } else { + is_unix_charset_unsafe = False; + } } /** -- cgit From acad182a3f13e55c2156994e599eb0b1e0f1960e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Mar 2004 21:59:11 +0000 Subject: Add function next_mb_char_size() that returns a size_t of the number of bytes in the mb character at a pointer. Will be useful in fixing check_path_syntax() to not use a "blacklist". Also re-added my (C) to reply.c. I mean, really - I've been adding code to the file for over 10 years and I recognise many of the fuctions as mine ! :-). Jeremy. (This used to be commit d2b2a39fd2f2e06cc4aebf081876985f0b28b477) --- source3/lib/charcnv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b06d869bcc..9ec6e73970 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1313,3 +1313,27 @@ size_t align_string(const void *base_ptr, const char *p, int flags) } return 0; } + +/**************************************************************** + Calculate the size (in bytes) of the next multibyte character in + our internal character set. Note that p must be pointing to a + valid mb char, not within one. +****************************************************************/ + +size_t next_mb_char_size(const char *s) +{ + size_t i; + + if (!(*s & 0x80)) + return 1; /* ascii. */ + + for ( i = 1; i <=4; i++ ) { + smb_ucs2_t uc; + if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) { + return i; + } + } + /* We're hosed - we don't know how big this is... */ + DEBUG(10,("next_mb_char_size: unknown size at string %s\n", s)); + return 1; +} -- cgit From aa2e306a015ad070cf4bf8eb531f1871803bb016 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Mar 2004 02:08:31 +0000 Subject: Change check_path_syntax() to use the new next_mb_char_size() function to make it generic. Remove the mb-codepage "blacklist". Alexander, please check this fix as it reverts your blacklist changes, but I'm hoping it fixes the problem in a more generic way for all charsets. I'm not trying to trample on your (excellent!) work here, just make things more generic without special cases. Jeremy. (This used to be commit 5a9324525acc02e6bf14528679816b35929a564e) --- source3/lib/charcnv.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9ec6e73970..ad15788b84 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -41,15 +41,6 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */ -/* Unsafe unix charsets which could contain '\\' as second byte of mb character */ -static const char *conv_unsafe_charsets[] = { - "CP932", - "EUC-JP", - NULL}; -/* Global variable which is set to True in init_iconv() if unix charset is unsafe - w.r.t. '\\' in second byte of mb character. Otherwise it is set to False. -*/ -BOOL is_unix_charset_unsafe; /** * Return the name of a charset to give to iconv(). @@ -114,7 +105,6 @@ void init_iconv(void) { int c1, c2; BOOL did_reload = False; - const char **unsafe_charset = conv_unsafe_charsets; /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ @@ -156,16 +146,6 @@ void init_iconv(void) init_valid_table(); conv_silent = False; } - - while(*unsafe_charset && strcmp(*unsafe_charset, conv_handles[CH_UCS2][CH_UNIX]->to_name)) { - unsafe_charset++; - } - - if (*unsafe_charset) { - is_unix_charset_unsafe = True; - } else { - is_unix_charset_unsafe = False; - } } /** @@ -1330,6 +1310,10 @@ size_t next_mb_char_size(const char *s) for ( i = 1; i <=4; i++ ) { smb_ucs2_t uc; if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) { +#if 0 /* JRATEST */ + DEBUG(10,("next_mb_char_size: size %u at string %s\n", + (unsigned int)i, s)); +#endif return i; } } -- cgit From 41ea0d35aeb984cbd3bc3baf96594ab6b67c70e2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Mar 2004 19:23:48 +0000 Subject: Remove excess logging when probing for the length of the next mb char. Jeremy. (This used to be commit 6339c4690aef7692571dd4c65dd0a12d56a7ffab) --- source3/lib/charcnv.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ad15788b84..f6028bb134 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1307,6 +1307,7 @@ size_t next_mb_char_size(const char *s) if (!(*s & 0x80)) return 1; /* ascii. */ + conv_silent = True; for ( i = 1; i <=4; i++ ) { smb_ucs2_t uc; if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) { @@ -1314,10 +1315,12 @@ size_t next_mb_char_size(const char *s) DEBUG(10,("next_mb_char_size: size %u at string %s\n", (unsigned int)i, s)); #endif + conv_silent = False; return i; } } /* We're hosed - we don't know how big this is... */ DEBUG(10,("next_mb_char_size: unknown size at string %s\n", s)); + conv_silent = False; return 1; } -- cgit From c66f52a5ac89c6b5c2d51653d2c012a9171cb56b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Mar 2004 17:58:50 +0000 Subject: Correctness patch from fumiya@miraclelinux.com to count characters correctly, doesn't affect what got put on the wire. Jeremy. (This used to be commit e8b68ef965ea2e3bed41cb397ef32df05c631e92) --- source3/lib/charcnv.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index f6028bb134..11b1448f1e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -839,6 +839,9 @@ size_t push_ascii_nstring(void *dest, const char *src) smb_panic("failed to create UCS2 buffer"); } + /* We're using buffer_len below to count ucs2 characters, not bytes. */ + buffer_len /= sizeof(smb_ucs2_t); + dest_len = 0; for (i = 0; buffer[i] != 0 && (i < buffer_len); i++) { unsigned char mb[10]; -- cgit From fe160f5b723b6ac08552d918e80aa85ce974d876 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Apr 2004 19:42:36 +0000 Subject: "Fixing my FORTRAN". Ensure we always have some valid char converter for the neccessary types before we will run at all. If we can't get one, use ASCII but complain mightily. Jeremy. (This used to be commit 37dd5e52f61e7ba1facb726ac70fc75e22608103) --- source3/lib/charcnv.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 11b1448f1e..b9791931a3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -130,9 +130,21 @@ void init_iconv(void) conv_handles[c1][c2] = smb_iconv_open(n2,n1); if (conv_handles[c1][c2] == (smb_iconv_t)-1) { - DEBUG(0,("Conversion from %s to %s not supported\n", + DEBUG(0,("init_iconv: Conversion from %s to %s not supported\n", charset_name((charset_t)c1), charset_name((charset_t)c2))); - conv_handles[c1][c2] = NULL; + if (c1 != CH_UCS2) { + n1 = "ASCII"; + } + if (c2 != CH_UCS2) { + n2 = "ASCII"; + } + DEBUG(0,("init_iconv: Attempting to replace with conversion from %s to %s\n", + n1, n2 )); + conv_handles[c1][c2] = smb_iconv_open(n2,n1); + if (!conv_handles[c1][c2]) { + DEBUG(0,("init_iconv: Conversion from %s to %s failed", n1, n2)); + smb_panic("init_iconv: conv_handle initialization failed."); + } } } } @@ -477,8 +489,6 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); - if (allow_bad_conv) - goto use_as_is; return (size_t)-1; } -- cgit From 5a3bc12683c6a21567a45ae927af6458dfd03263 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 26 May 2004 14:19:28 +0000 Subject: r907: fixing browse.dat bug -- don't include the resouce byte from the netbios name when pulling a string from a packet (jra, please double check this (This used to be commit c9bef86b8b422c5cbb6e3e5d2abb96c6e4560c1e) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b9791931a3..3d7678c34c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -932,7 +932,7 @@ size_t pull_ascii_fstring(char *dest, const void *src) size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src) { - return pull_ascii(dest, src, dest_len, sizeof(nstring), STR_TERMINATE); + return pull_ascii(dest, src, dest_len, sizeof(nstring)-1, STR_TERMINATE); } /** -- cgit From 16de9d9711d5de8b2877b367e1d86ad3844d5d09 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Aug 2004 02:05:38 +0000 Subject: r1684: Patch for bug #1578 based on fix from Alexander E. Patrakov, . Main change, hardcode replacement char to '_' as I really don't want a new parameter. Jeremy. (This used to be commit db3dde026b84aa28c2d7a32249488f203e362497) --- source3/lib/charcnv.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 3d7678c34c..6cbf7562b0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -23,6 +23,13 @@ */ #include "includes.h" +/* We can parameterize this if someone complains.... JRA. */ + +char lp_failed_convert_char(void) +{ + return '_'; +} + /** * @file * @@ -259,11 +266,11 @@ static size_t convert_string_internal(charset_t from, charset_t to, return destlen - o_len; if (from == CH_UCS2 && to != CH_UCS2) { - /* Can't convert from ucs2 to multibyte. Just truncate this char to ascii. */ + /* Can't convert from ucs2 to multibyte. Replace with the default fail char. */ if (i_len < 2) return destlen - o_len; if (i_len >= 2) { - *outbuf = inbuf[0]; + *outbuf = lp_failed_convert_char(); outbuf++; o_len--; @@ -279,11 +286,11 @@ static size_t convert_string_internal(charset_t from, charset_t to, goto again; } else if (from != CH_UCS2 && to == CH_UCS2) { - /* Can't convert to ucs2 - just widen by adding zero. */ + /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */ if (o_len < 2) return destlen - o_len; - outbuf[0] = inbuf[0]; + outbuf[0] = lp_failed_convert_char(); outbuf[1] = '\0'; inbuf++; @@ -299,9 +306,9 @@ static size_t convert_string_internal(charset_t from, charset_t to, goto again; } else if (from != CH_UCS2 && to != CH_UCS2) { - /* Failed multibyte to multibyte. Just copy 1 char and + /* Failed multibyte to multibyte. Just copy the default fail char and try again. */ - outbuf[0] = inbuf[0]; + outbuf[0] = lp_failed_convert_char(); inbuf++; i_len--; @@ -581,12 +588,12 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, goto out; if (from == CH_UCS2 && to != CH_UCS2) { - /* Can't convert from ucs2 to multibyte. Just truncate this char to ascii. */ + /* Can't convert from ucs2 to multibyte. Just use the default fail char. */ if (i_len < 2) goto out; if (i_len >= 2) { - *outbuf = inbuf[0]; + *outbuf = lp_failed_convert_char(); outbuf++; o_len--; @@ -602,11 +609,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, goto again; } else if (from != CH_UCS2 && to == CH_UCS2) { - /* Can't convert to ucs2 - just widen by adding zero. */ + /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */ if (o_len < 2) goto out; - outbuf[0] = inbuf[0]; + outbuf[0] = lp_failed_convert_char(); outbuf[1] = '\0'; inbuf++; @@ -622,9 +629,9 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, goto again; } else if (from != CH_UCS2 && to != CH_UCS2) { - /* Failed multibyte to multibyte. Just copy 1 char and + /* Failed multibyte to multibyte. Just copy the default fail char and try again. */ - outbuf[0] = inbuf[0]; + outbuf[0] = lp_failed_convert_char(); inbuf++; i_len--; -- 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/charcnv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 6cbf7562b0..21d34f30cb 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -56,7 +56,7 @@ static const char *charset_name(charset_t ch) { const char *ret = NULL; - if (ch == CH_UCS2) ret = "UCS-2LE"; + if (ch == CH_UCS2) ret = "UTF-16LE"; else if (ch == CH_UNIX) ret = lp_unix_charset(); else if (ch == CH_DOS) ret = lp_dos_charset(); else if (ch == CH_DISPLAY) ret = lp_display_charset(); @@ -116,10 +116,10 @@ void init_iconv(void) /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ if (!conv_handles[CH_UNIX][CH_UCS2]) - conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open("UCS-2LE", "ASCII"); + conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open(charset_name(CH_UCS2), "ASCII"); if (!conv_handles[CH_UCS2][CH_UNIX]) - conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); + conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UCS2)); for (c1=0;c1 Date: Fri, 17 Sep 2004 19:53:12 +0000 Subject: r2392: Steal the nicer error message from Samba4 :-). Jeremy. (This used to be commit afa88868b76a6e825bc45f8d405d4b3f557fdfdb) --- source3/lib/charcnv.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 21d34f30cb..40004826b4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -229,14 +229,18 @@ static size_t convert_string_internal(charset_t from, charset_t to, break; case E2BIG: reason="No more room"; - if (!conv_silent) - DEBUG(3, ("convert_string_internal: Required %lu, available %lu\n", - (unsigned long)srclen, (unsigned long)destlen)); - /* we are not sure we need srclen bytes, - may be more, may be less. - We only know we need more than destlen - bytes ---simo */ - break; + if (!conv_silent) { + if (from == CH_UNIX) { + DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u - '%s'\n", + charset_name(from), charset_name(to), + (unsigned int)srclen, (unsigned int)destlen, (const char *)src)); + } else { + DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u\n", + charset_name(from), charset_name(to), + (unsigned int)srclen, (unsigned int)destlen)); + } + } + break; case EILSEQ: reason="Illegal multibyte sequence"; if (!conv_silent) -- cgit From 17ab9e8db1ddad310d7e2e565a9109d9a83cce72 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Sep 2004 23:56:22 +0000 Subject: r2610: Even if we only use the fast-path (ascii only) then we still need to set errno = E2BIG when we overflow. Jeremy. (This used to be commit 7b0560dcccbd44f1f7b67ba1d46f6a5680b6b47c) --- source3/lib/charcnv.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 40004826b4..0fe1f15ed5 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -394,6 +394,13 @@ size_t convert_string(charset_t from, charset_t to, #endif } } + if (!dlen) { + /* Even if we fast path we should note if we ran out of room. */ + if (((slen != (size_t)-1) && slen) || + ((slen == (size_t)-1) && lastp)) { + errno = E2BIG; + } + } return retval; } else if (from == CH_UCS2 && to != CH_UCS2) { const unsigned char *p = (const unsigned char *)src; @@ -423,6 +430,13 @@ size_t convert_string(charset_t from, charset_t to, #endif } } + if (!dlen) { + /* Even if we fast path we should note if we ran out of room. */ + if (((slen != (size_t)-1) && slen) || + ((slen == (size_t)-1) && lastp)) { + errno = E2BIG; + } + } return retval; } else if (from != CH_UCS2 && to == CH_UCS2) { const unsigned char *p = (const unsigned char *)src; @@ -452,6 +466,13 @@ size_t convert_string(charset_t from, charset_t to, #endif } } + if (!dlen) { + /* Even if we fast path we should note if we ran out of room. */ + if (((slen != (size_t)-1) && slen) || + ((slen == (size_t)-1) && lastp)) { + errno = E2BIG; + } + } return retval; } -- cgit From b74b9c5037c37c42c3337608774c8b0ed2611bbc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Nov 2004 19:03:17 +0000 Subject: r3857: Shut up gcc about erroneous "used uninitialised" warning. Jeremy. (This used to be commit ac9b91d805c3ee68119d4b25ab05ed043f0ab8f1) --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0fe1f15ed5..95e24609cd 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -372,7 +372,7 @@ size_t convert_string(charset_t from, charset_t to, unsigned char *q = (unsigned char *)dest; size_t slen = srclen; size_t dlen = destlen; - unsigned char lastp; + unsigned char lastp = '\0'; size_t retval = 0; /* If all characters are ascii, fast path here. */ @@ -408,7 +408,7 @@ size_t convert_string(charset_t from, charset_t to, size_t retval = 0; size_t slen = srclen; size_t dlen = destlen; - unsigned char lastp; + unsigned char lastp = '\0'; /* If all characters are ascii, fast path here. */ while (((slen == (size_t)-1) || (slen >= 2)) && dlen) { @@ -444,7 +444,7 @@ size_t convert_string(charset_t from, charset_t to, size_t retval = 0; size_t slen = srclen; size_t dlen = destlen; - unsigned char lastp; + unsigned char lastp = '\0'; /* If all characters are ascii, fast path here. */ while (slen && (dlen >= 2)) { -- 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/charcnv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 95e24609cd..e8ceaf39b7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -538,9 +538,9 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } if (ctx) - ob = (char *)talloc_realloc(ctx, ob, destlen); + ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); else - ob = (char *)Realloc(ob, destlen); + ob = (char *)SMB_REALLOC(ob, destlen); if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); @@ -588,9 +588,9 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, destlen = destlen - o_len; if (ctx) - *dest = (char *)talloc_realloc(ctx,ob,destlen); + *dest = (char *)TALLOC_REALLOC(ctx,ob,destlen); else - *dest = (char *)Realloc(ob,destlen); + *dest = (char *)SMB_REALLOC(ob,destlen); if (destlen && !*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); if (!ctx) @@ -763,7 +763,7 @@ char *strdup_upper(const char *s) } } - return strdup(out_buffer); + return SMB_STRDUP(out_buffer); } size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) -- cgit From 92a7eb69d393e10d4fa422871d68a0728692cd38 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Dec 2004 05:49:48 +0000 Subject: r4126: Fix from Björn Jacke for bugid #2040 - ensure the locale is reset to C to get ASCII-compatible toupper/lower functions. Jeremy. (This used to be commit 8e1b1693abf1e6eb46b23a5fa56776fc2ede7982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/lib/charcnv.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index e8ceaf39b7..b9b9d90db6 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -84,6 +84,15 @@ static const char *charset_name(charset_t ch) } ret = ln; } +#ifdef HAVE_SETLOCALE + /* We set back the locale to C to get ASCII-compatible toupper/lower functions. + For now we do not need any other POSIX localisations anyway. When we should + really need localized string functions one day we need to write our own + ascii_tolower etc. + */ + setlocale(LC_ALL, "C"); + #endif + #endif if (!ret || !*ret) ret = "ASCII"; -- cgit From 442b9f3e87ee7f9fe8c100cd37c9591733e290e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Mar 2005 02:14:38 +0000 Subject: r5933: We were handling setting of EA's incorrectly - we should be able to set a list. Also not converting names from DOS CP to UNIX CP correctly. This code doesn't quite work yet but it's a work in progress to be fixed tomorrow (don't want to lose it). Jeremy. (This used to be commit 22fca746576810c5408540031a9603625a66cd75) --- source3/lib/charcnv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b9b9d90db6..4fbad0f3d1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1268,6 +1268,21 @@ size_t pull_utf8_allocate(char **dest, const char *src) return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); } +/** + * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True); +} + /** Copy a string from a char* src to a unicode or ascii dos codepage destination choosing unicode or ascii based on the -- cgit From d1f91f7c723733113b4e9792042101c80dfc064c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:46:46 +0000 Subject: r12043: It's amazing the warnings you find when compiling on a 64-bit box with gcc4 and -O6... Fix a bunch of C99 dereferencing type-punned pointer will break strict-aliasing rules errors. Also added prs_int32 (not uint32...) as it's needed in one place. Find places where prs_uint32 was being used to marshall/unmarshall a time_t (a big no no on 64-bits). More warning fixes to come. Thanks to Volker for nudging me to compile like this. Jeremy. (This used to be commit c65b752604f8f58abc4e7ae8514dc2c7f086271c) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4fbad0f3d1..0c806167f4 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -781,7 +781,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, - (void **) &buffer, True); + (void **)(void *)&buffer, True); if (size == (size_t)-1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } -- cgit From 5a4881bf396e691524329bcd6aa1ae4a7f4084ec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Dec 2005 20:52:36 +0000 Subject: r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") and replace calls to isupper/islower/toupper/tolower with ASCII equivalents (mapping into _w variants). Jeremy. (This used to be commit c2752347eb2deeb2798c580ec7fc751a847717e9) --- source3/lib/charcnv.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0c806167f4..c4eeab135e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -84,15 +84,6 @@ static const char *charset_name(charset_t ch) } ret = ln; } -#ifdef HAVE_SETLOCALE - /* We set back the locale to C to get ASCII-compatible toupper/lower functions. - For now we do not need any other POSIX localisations anyway. When we should - really need localized string functions one day we need to write our own - ascii_tolower etc. - */ - setlocale(LC_ALL, "C"); - #endif - #endif if (!ret || !*ret) ret = "ASCII"; @@ -747,7 +738,7 @@ char *strdup_upper(const char *s) while (1) { if (*p & 0x80) break; - *q++ = toupper(*p); + *q++ = toupper_ascii(*p); if (!*p) break; p++; -- cgit From 894358a8f3e338b339b6c37233edef794b312087 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Mar 2006 06:31:04 +0000 Subject: r13915: Fixed a very interesting class of realloc() bugs found by Coverity. realloc can return NULL in one of two cases - (1) the realloc failed, (2) realloc succeeded but the new size requested was zero, in which case this is identical to a free() call. The error paths dealing with these two cases should be different, but mostly weren't. Secondly the standard idiom for dealing with realloc when you know the new size is non-zero is the following : tmp = realloc(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } However, there were *many* *many* places in Samba where we were using the old (broken) idiom of : p = realloc(p, size) if (!p) { return error; } which will leak the memory pointed to by p on realloc fail. This commit (hopefully) fixes all these cases by moving to a standard idiom of : p = SMB_REALLOC(p, size) if (!p) { return error; } Where if the realloc returns null due to the realloc failing or size == 0 we *guarentee* that the storage pointed to by p has been freed. This allows me to remove a lot of code that was dealing with the standard (more verbose) method that required a tmp pointer. This is almost always what you want. When a realloc fails you never usually want the old memory, you want to free it and get into your error processing asap. For the 11 remaining cases where we really do need to keep the old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR, which can be used as follows : tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the pointer p, even on size == 0 or realloc fail. All this is done by a hidden extra argument to Realloc(), BOOL free_old_on_error which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR macros (and their array counterparts). It remains to be seen what this will do to our Coverity bug count :-). Jeremy. (This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0) --- source3/lib/charcnv.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c4eeab135e..ae04fd9ffb 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -537,19 +537,17 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, destlen = destlen * 2; } - if (ctx) + if (ctx) { ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); - else + } else { ob = (char *)SMB_REALLOC(ob, destlen); + } if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - if (!ctx) - SAFE_FREE(outbuf); return (size_t)-1; - } else { - outbuf = ob; } + outbuf = ob; i_len = srclen; o_len = destlen; @@ -587,17 +585,18 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, out: destlen = destlen - o_len; - if (ctx) - *dest = (char *)TALLOC_REALLOC(ctx,ob,destlen); - else - *dest = (char *)SMB_REALLOC(ob,destlen); - if (destlen && !*dest) { + if (ctx) { + ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); + } else { + ob = (char *)SMB_REALLOC(ob,destlen); + } + + if (destlen && !ob) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); - if (!ctx) - SAFE_FREE(ob); return (size_t)-1; } + *dest = ob; return destlen; use_as_is: -- cgit From bbf666e447132a5f6b206ddf9ca918298b756392 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 8 Apr 2006 17:25:31 +0000 Subject: r15003: patch based on code from Arkady Glabek to ensure that global memory is freed when unloading pam_winbind.so (needs more testing on non-linux platforms) (This used to be commit 1e0b79e591d70352a96e0a0487d8f394dc7b36ba) --- source3/lib/charcnv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ae04fd9ffb..097d746a63 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -101,6 +101,23 @@ void lazy_initialize_conv(void) } } +/** + * Destroy global objects allocated by init_iconv() + **/ +void gfree_charcnv(void) +{ + int c1, c2; + + for (c1=0;c1 Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/lib/charcnv.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 097d746a63..fffdf010a0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -516,13 +516,14 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) + void const *src, size_t srclen, void *dst, BOOL allow_bad_conv) { size_t i_len, o_len, destlen = MAX(srclen, 512); size_t retval; const char *inbuf = (const char *)src; char *outbuf = NULL, *ob = NULL; smb_iconv_t descriptor; + void **dest = (void **)dst; *dest = NULL; @@ -702,9 +703,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * * @returns Size in bytes of the converted string; or -1 in case of error. **/ -static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) +size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + BOOL allow_bad_conv) { + void **dest = (void **)dst; size_t dest_len; *dest = NULL; @@ -944,9 +947,9 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (flags & STR_TERMINATE) { if (src_len == (size_t)-1) { - src_len = strlen(src) + 1; + src_len = strlen((const char *)src) + 1; } else { - size_t len = strnlen(src, src_len); + size_t len = strnlen((const char *)src, src_len); if (len < src_len) len++; src_len = len; @@ -1034,7 +1037,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ len += ret; if (flags & STR_UPPER) { - smb_ucs2_t *dest_ucs2 = dest; + smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest; size_t i; for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) { smb_ucs2_t v = toupper_w(dest_ucs2[i]); @@ -1178,7 +1181,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (flags & STR_TERMINATE) { /* src_len -1 is the default for null terminated strings. */ if (src_len != (size_t)-1) { - size_t len = strnlen_w(src, src_len/2); + size_t len = strnlen_w((const smb_ucs2_t *)src, + src_len/2); if (len < src_len/2) len++; src_len = len*2; -- cgit From f18c9365caaad75c0f4c9e26b89327a75cfcb3e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Sep 2006 17:00:07 +0000 Subject: r18787: Fix the strlen_m and strlen_m_term code by merging in (and using elsewhere) next_codepoint from Samba4. Jerry please test. Jeremy. (This used to be commit ece00b70a4621633f1ac9e576c4bbe332031de09) --- source3/lib/charcnv.c | 99 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 23 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index fffdf010a0..c5ce3ca8c7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1374,33 +1374,86 @@ size_t align_string(const void *base_ptr, const char *p, int flags) return 0; } -/**************************************************************** - Calculate the size (in bytes) of the next multibyte character in - our internal character set. Note that p must be pointing to a - valid mb char, not within one. -****************************************************************/ +/* + Return the unicode codepoint for the next multi-byte CH_UNIX character + in the string. The unicode codepoint (codepoint_t) is an unsinged 32 bit value. -size_t next_mb_char_size(const char *s) + Also return the number of bytes consumed (which tells the caller + how many bytes to skip to get to the next CH_UNIX character). + + Return INVALID_CODEPOINT if the next character cannot be converted. +*/ + +codepoint_t next_codepoint(const char *str, size_t *size) { - size_t i; + /* It cannot occupy more than 4 bytes in UTF16 format */ + uint8_t buf[4]; + smb_iconv_t descriptor; + size_t ilen_orig; + size_t ilen; + size_t olen; + char *outbuf; + + if ((str[0] & 0x80) == 0) { + *size = 1; + return (codepoint_t)str[0]; + } - if (!(*s & 0x80)) - return 1; /* ascii. */ + /* We assume that no multi-byte character can take + more than 5 bytes. This is OK as we only + support codepoints up to 1M */ - conv_silent = True; - for ( i = 1; i <=4; i++ ) { - smb_ucs2_t uc; - if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) { -#if 0 /* JRATEST */ - DEBUG(10,("next_mb_char_size: size %u at string %s\n", - (unsigned int)i, s)); -#endif - conv_silent = False; - return i; + ilen_orig = strnlen(str, 5); + ilen = ilen_orig; + + lazy_initialize_conv(); + + /* CH_UCS2 == UTF16-LE. */ + descriptor = conv_handles[CH_UNIX][CH_UCS2]; + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { + *size = 1; + return INVALID_CODEPOINT; + } + + /* This looks a little strange, but it is needed to cope + with codepoints above 64k which are encoded as per RFC2781. */ + olen = 2; + outbuf = (char *)buf; + smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); + if (olen == 2) { + /* We failed to convert to a 2 byte character. + See if we can convert to a 4 UTF16-LE byte char encoding. + */ + olen = 4; + outbuf = (char *)buf; + smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); + if (olen == 4) { + /* We didn't convert any bytes */ + *size = 1; + return INVALID_CODEPOINT; } + olen = 4 - olen; + } else { + olen = 2 - olen; } - /* We're hosed - we don't know how big this is... */ - DEBUG(10,("next_mb_char_size: unknown size at string %s\n", s)); - conv_silent = False; - return 1; + + *size = ilen_orig - ilen; + + if (olen == 2) { + /* 2 byte, UTF16-LE encoded value. */ + return (codepoint_t)SVAL(buf, 0); + } + if (olen == 4) { + /* Decode a 4 byte UTF16-LE character manually. + See RFC2871 for the encoding machanism. + */ + codepoint_t w1 = SVAL(buf,0) & ~0xD800; + codepoint_t w2 = SVAL(buf,2) & ~0xDC00; + + return (codepoint_t)0x10000 + + (w1 << 10) + w2; + } + + /* no other length is valid */ + return INVALID_CODEPOINT; } -- cgit From 3a60a6743262ab2ab221e0fe13ef6b510424ca3f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Sep 2006 18:37:09 +0000 Subject: r18793: Fix BE string handling in the auto-generated code. Should now work again with ASU. Jeremy. (This used to be commit 53e97bf92817b6cfc3f93c999a81ef8ad49a1609) --- source3/lib/charcnv.c | 85 +++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 36 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c5ce3ca8c7..ebc97033ac 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -56,7 +56,8 @@ static const char *charset_name(charset_t ch) { const char *ret = NULL; - if (ch == CH_UCS2) ret = "UTF-16LE"; + if (ch == CH_UTF16LE) ret = "UTF-16LE"; + else if (ch == CH_UTF16BE) ret = "UTF-16BE"; else if (ch == CH_UNIX) ret = lp_unix_charset(); else if (ch == CH_DOS) ret = lp_dos_charset(); else if (ch == CH_DISPLAY) ret = lp_display_charset(); @@ -132,11 +133,11 @@ void init_iconv(void) /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ - if (!conv_handles[CH_UNIX][CH_UCS2]) - conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open(charset_name(CH_UCS2), "ASCII"); + if (!conv_handles[CH_UNIX][CH_UTF16LE]) + conv_handles[CH_UNIX][CH_UTF16LE] = smb_iconv_open(charset_name(CH_UTF16LE), "ASCII"); - if (!conv_handles[CH_UCS2][CH_UNIX]) - conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UCS2)); + if (!conv_handles[CH_UTF16LE][CH_UNIX]) + conv_handles[CH_UTF16LE][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UTF16LE)); for (c1=0;c1= 2) { @@ -306,8 +310,10 @@ static size_t convert_string_internal(charset_t from, charset_t to, /* Keep trying with the next char... */ goto again; - } else if (from != CH_UCS2 && to == CH_UCS2) { - /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */ + } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) { + /* Can't convert to UTF16LE - just widen by adding the + default fail char then zero. + */ if (o_len < 2) return destlen - o_len; @@ -326,7 +332,8 @@ static size_t convert_string_internal(charset_t from, charset_t to, /* Keep trying with the next char... */ goto again; - } else if (from != CH_UCS2 && to != CH_UCS2) { + } else if (from != CH_UTF16LE && from != CH_UTF16BE && + to != CH_UTF16LE && to != CH_UTF16BE) { /* Failed multibyte to multibyte. Just copy the default fail char and try again. */ outbuf[0] = lp_failed_convert_char(); @@ -384,7 +391,7 @@ size_t convert_string(charset_t from, charset_t to, if (srclen == 0) return 0; - if (from != CH_UCS2 && to != CH_UCS2) { + if (from != CH_UTF16LE && from != CH_UTF16BE && to != CH_UTF16LE && to != CH_UTF16BE) { const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t slen = srclen; @@ -419,7 +426,7 @@ size_t convert_string(charset_t from, charset_t to, } } return retval; - } else if (from == CH_UCS2 && to != CH_UCS2) { + } else if (from == CH_UTF16LE && to != CH_UTF16LE) { const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; @@ -455,7 +462,7 @@ size_t convert_string(charset_t from, charset_t to, } } return retval; - } else if (from != CH_UCS2 && to == CH_UCS2) { + } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) { const unsigned char *p = (const unsigned char *)src; unsigned char *q = (unsigned char *)dest; size_t retval = 0; @@ -629,8 +636,12 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (o_len == 0 || i_len == 0) goto out; - if (from == CH_UCS2 && to != CH_UCS2) { - /* Can't convert from ucs2 to multibyte. Just use the default fail char. */ + if (((from == CH_UTF16LE)||(from == CH_UTF16BE)) && + ((to != CH_UTF16LE)||(to != CH_UTF16BE))) { + /* Can't convert from utf16 any endian to multibyte. + Replace with the default fail char. + */ + if (i_len < 2) goto out; @@ -650,8 +661,10 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, /* Keep trying with the next char... */ goto again; - } else if (from != CH_UCS2 && to == CH_UCS2) { - /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */ + } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) { + /* Can't convert to UTF16LE - just widen by adding the + default fail char then zero. + */ if (o_len < 2) goto out; @@ -670,9 +683,10 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, /* Keep trying with the next char... */ goto again; - } else if (from != CH_UCS2 && to != CH_UCS2) { + } else if (from != CH_UTF16LE && from != CH_UTF16BE && + to != CH_UTF16LE && to != CH_UTF16BE) { /* Failed multibyte to multibyte. Just copy the default fail char and - try again. */ + try again. */ outbuf[0] = lp_failed_convert_char(); inbuf++; @@ -733,7 +747,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) return srclen; } - size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True); + size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True); free(buffer); return size; } @@ -769,14 +783,14 @@ char *strdup_upper(const char *s) /* MB case. */ size_t size; wpstring buffer; - size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer), True); + size = convert_string(CH_UNIX, CH_UTF16LE, s, -1, buffer, sizeof(buffer), True); if (size == (size_t)-1) { return NULL; } strupper_w(buffer); - size = convert_string(CH_UCS2, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); + size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); if (size == (size_t)-1) { return NULL; } @@ -790,7 +804,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer = NULL; - size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, + size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, (void **)(void *)&buffer, True); if (size == (size_t)-1 || !buffer) { smb_panic("failed to create UCS2 buffer"); @@ -799,7 +813,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) SAFE_FREE(buffer); return srclen; } - size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True); + size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True); SAFE_FREE(buffer); return size; } @@ -907,7 +921,7 @@ size_t push_ascii_nstring(void *dest, const char *src) for (i = 0; buffer[i] != 0 && (i < buffer_len); i++) { unsigned char mb[10]; /* Convert one smb_ucs2_t character at a time. */ - size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False); + size_t mb_len = convert_string(CH_UTF16LE, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False); if ((mb_len != (size_t)-1) && (dest_len + mb_len <= MAX_NETBIOSNAME_LEN - 1)) { memcpy((char *)dest + dest_len, mb, mb_len); dest_len += mb_len; @@ -1029,7 +1043,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; - ret = convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { return 0; } @@ -1065,7 +1079,7 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); } @@ -1083,7 +1097,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True); + return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); } /** @@ -1193,7 +1207,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (src_len != (size_t)-1) src_len &= ~1; - ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { return 0; } @@ -1231,7 +1245,7 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); } /** @@ -1246,7 +1260,7 @@ size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); } /** @@ -1408,8 +1422,7 @@ codepoint_t next_codepoint(const char *str, size_t *size) lazy_initialize_conv(); - /* CH_UCS2 == UTF16-LE. */ - descriptor = conv_handles[CH_UNIX][CH_UCS2]; + descriptor = conv_handles[CH_UNIX][CH_UTF16LE]; if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { *size = 1; return INVALID_CODEPOINT; -- cgit From f1964048a5ce7b71d89953ba77ddeb5f34d91747 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 25 Sep 2006 16:19:30 +0000 Subject: r18897: Fix valgrind bug found by Volker. Jeremy. (This used to be commit db458d3e8bdd11812cea34128df6a3c29baa59c3) --- source3/lib/charcnv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ebc97033ac..3d02988a97 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1053,7 +1053,11 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ if (flags & STR_UPPER) { smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest; size_t i; - for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) { + + /* We check for i < (ret / 2) below as the dest string isn't null + terminated if STR_TERMINATE isn't set. */ + + for (i = 0; i < (ret / 2) && i < (dest_len / 2) && dest_ucs2[i]; i++) { smb_ucs2_t v = toupper_w(dest_ucs2[i]); if (v != dest_ucs2[i]) { dest_ucs2[i] = v; -- cgit From 798af9e0c86976245c36ea1f0c7171e9ab663da7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 7 May 2007 19:27:46 +0000 Subject: r22754: When processing a string, ensure we don't write one past the terminating NULL if we've already processed the null in iconv. Jerry, once I get confirmation from Thomas Bork this needs to be in 3.0.25 final. Tests fine with valgrind here. Jeremy. (This used to be commit 14b167ef6e0f2100bd9cdd05c4457e57e952fa5e) --- source3/lib/charcnv.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 3d02988a97..8d5fbc8118 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -972,13 +972,18 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { + ret = 0; dest_len = 0; } - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - else + if (dest_len && ret) { + /* Did we already process the terminating zero ? */ + if (dest[MIN(ret-1, dest_len-1)] != 0) { + dest[MIN(ret, dest_len-1)] = 0; + } + } else { dest[0] = 0; + } return src_len; } @@ -1219,10 +1224,14 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (src_len == (size_t)-1) src_len = ret*2; - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - else + if (dest_len && ret) { + /* Did we already process the terminating zero ? */ + if (dest[MIN(ret-1, dest_len-1)] != 0) { + dest[MIN(ret, dest_len-1)] = 0; + } + } else { dest[0] = 0; + } return src_len; } -- cgit From b1ce226af8b61ad7e3c37860a59c6715012e738b Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 15 Jun 2007 21:58:49 +0000 Subject: r23510: Tidy calls to smb_panic by removing trailing newlines. Print the failed expression in SMB_ASSERT. (This used to be commit 171dc060e2a576d724eed1ca65636bdafffd7713) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 8d5fbc8118..35343b2f0a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -168,7 +168,7 @@ void init_iconv(void) conv_handles[c1][c2] = smb_iconv_open(n2,n1); if (!conv_handles[c1][c2]) { DEBUG(0,("init_iconv: Conversion from %s to %s failed", n1, n2)); - smb_panic("init_iconv: conv_handle initialization failed."); + smb_panic("init_iconv: conv_handle initialization failed"); } } } -- cgit From 971b640e0cb8bac510771d126454a8e4d2eff507 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 29 Jun 2007 17:27:59 +0000 Subject: r23660: Anybody know what check_dos_char() was used for? It wasn't called at all, so it's gone. With it 8k bss went away. (This used to be commit 7e9a4c39a5ce620f8eac74d0ae4dd80b96c81aca) --- source3/lib/charcnv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 35343b2f0a..7be073fafc 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -179,7 +179,6 @@ void init_iconv(void) * codepage changes? */ /* XXX: Is the did_reload test too strict? */ conv_silent = True; - init_doschar_table(); init_valid_table(); conv_silent = False; } -- cgit From ef8706acd1a880a811b65310d01f309d36d9d47e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 29 Jun 2007 17:51:31 +0000 Subject: r23662: According to simo, check_dos_char is needed (This used to be commit c195eccefea69c17169c350a13bbfe845fc6fc44) --- source3/lib/charcnv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7be073fafc..35343b2f0a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -179,6 +179,7 @@ void init_iconv(void) * codepage changes? */ /* XXX: Is the did_reload test too strict? */ conv_silent = True; + init_doschar_table(); init_valid_table(); conv_silent = False; } -- cgit From fcda5b589633b96415890c569bf23e3e284e0916 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jul 2007 16:33:37 +0000 Subject: r23726: Explicitly pass down the FLAGS2 field to srvstr_pull_buf. The next checkin will pull this up to srvstr_get_path. At that point we can get more independent of the inbuf, the base_ptr in pull_string will only be used to satisfy UCS2 alignment constraints. (This used to be commit 836782b07bf133e9b2598c4a089f1c810e4c7754) --- source3/lib/charcnv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 35343b2f0a..5ca7f201c2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1376,16 +1376,24 @@ size_t push_string_fn(const char *function, unsigned int line, const void *base_ The resulting string in "dest" is always null terminated. **/ -size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +size_t pull_string_fn(const char *function, unsigned int line, + const void *base_ptr, uint16 smb_flags2, char *dest, + const void *src, size_t dest_len, size_t src_len, + int flags) { #ifdef DEVELOPER if (dest_len != (size_t)-1) clobber_region(function, line, dest, dest_len); #endif + if ((base_ptr == NULL) && ((flags & (STR_ASCII|STR_UNICODE)) == 0)) { + smb_panic("No base ptr to get flg2 and neither ASCII nor " + "UNICODE defined"); + } + if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ - (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { + (smb_flags2 & FLAGS2_UNICODE_STRINGS)))) { return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags); } return pull_ascii(dest, src, dest_len, src_len, flags); -- 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/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5ca7f201c2..226a105d48 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -8,7 +8,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/charcnv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 226a105d48..b48880a8ea 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -17,8 +17,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 e8dc2ea03d212bc4b4facc2a900f6a443365c390 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Jul 2007 01:22:09 +0000 Subject: r23858: Added srvstr_pull_buf_talloc() and srvstr_pull_talloc() calls and converted reply_tcon and reply_tconX to use them - to show the boilerplate usage (valgrind tested). In conjunction with Volker's srvstr_get_path_talloc() work this should allow us to start eliminating all pstrings/fstrings out of the main path processing code. I'll watch the build farm tonight... Jeremy. (This used to be commit b4eff3f68089f082781afcf90d43faa317949566) --- source3/lib/charcnv.c | 250 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 234 insertions(+), 16 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b48880a8ea..b71e15f44d 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1,21 +1,21 @@ -/* +/* Unix SMB/CIFS implementation. Character set conversion Extensions Copyright (C) Igor Vergeichik 2001 Copyright (C) Andrew Tridgell 2001 Copyright (C) Simo Sorce 2001 Copyright (C) Martin Pool 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 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, 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, see . @@ -33,7 +33,7 @@ char lp_failed_convert_char(void) * @file * * @brief Character-set conversion routines built on our iconv. - * + * * @note Samba's internal character set (at least in the 3.0 series) * is always the same as the one for the Unix filesystem. It is * not necessarily UTF-8 and may be different on machines that @@ -509,6 +509,7 @@ size_t convert_string(charset_t from, charset_t to, * Convert between character sets, allocating a new buffer for the result. * * @param ctx TALLOC_CTX to use to allocate with. If NULL use malloc. + * (this is a bad interface and needs fixing. JRA). * @param srclen length of source buffer. * @param dest always set at least to NULL * @note -1 is not accepted for srclen. @@ -516,7 +517,7 @@ size_t convert_string(charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. * * Ensure the srclen contains the terminating zero. - * + * * I hate the goto's in this function. It's embarressing..... * There has to be a cleaner way to do this. JRA. **/ @@ -603,6 +604,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (!conv_silent) DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf)); /* smb_panic(reason); */ + if (ctx) { + TALLOC_FREE(ob); + } else { + SAFE_FREE(ob); + } return (size_t)-1; } @@ -711,7 +717,7 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * Convert between character sets, allocating a new buffer using talloc for the result. * * @param srclen length of source buffer. - * @param dest always set at least to NULL + * @param dest always set at least to NULL * @note -1 is not accepted for srclen. * * @returns Size in bytes of the converted string; or -1 in case of error. @@ -736,7 +742,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; smb_ucs2_t *buffer; - + size = push_ucs2_allocate(&buffer, src); if (size == (size_t)-1) { smb_panic("failed to create UCS2 buffer"); @@ -745,7 +751,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) free(buffer); return srclen; } - + size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True); free(buffer); return size; @@ -788,7 +794,7 @@ char *strdup_upper(const char *s) } strupper_w(buffer); - + size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); if (size == (size_t)-1) { return NULL; @@ -802,7 +808,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; smb_ucs2_t *buffer = NULL; - + size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, (void **)(void *)&buffer, True); if (size == (size_t)-1 || !buffer) { @@ -826,21 +832,21 @@ char *strdup_lower(const char *s) size_t size; smb_ucs2_t *buffer = NULL; char *out_buffer; - + size = push_ucs2_allocate(&buffer, s); if (size == -1 || !buffer) { return NULL; } strlower_w(buffer); - + size = pull_ucs2_allocate(&out_buffer, buffer); SAFE_FREE(buffer); if (size == (size_t)-1) { return NULL; } - + return out_buffer; } @@ -987,6 +993,84 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, return src_len; } +/** + * Copy a string from a dos codepage source to a unix char* destination. + Talloc version. + Uses malloc if TALLOC_CTX is NULL (this is a bad interface and + needs fixing. JRA). + * + * The resulting string in "dest" is always null terminated. + * + * @param flags can have: + *
+ *
STR_TERMINATE
+ *
STR_TERMINATE means the string in @p src + * is null terminated, and src_len is ignored.
+ *
+ * + * @param src_len is the length of the source area in bytes. + * @returns the number of bytes occupied by the string in @p src. + **/ + +static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, + char **ppdest, + const void *src, + size_t src_len, + int flags) +{ + char *dest = NULL; + size_t dest_len = 0; + +#ifdef DEVELOPER + /* Ensure we never use the braindead "malloc" varient. */ + if (ctx == NULL) { + smb_panic("NULL talloc CTX in pull_ascii_base_talloc\n"); + } +#endif + + *ppdest = NULL; + + if (flags & STR_TERMINATE) { + if (src_len == (size_t)-1) { + src_len = strlen((const char *)src) + 1; + } else { + size_t len = strnlen((const char *)src, src_len); + if (len < src_len) + len++; + src_len = len; + } + /* Ensure we don't use an insane length from the client. */ + if (src_len >= 1024*1024) { + smb_panic("Bad src length in pull_ascii_base_talloc\n"); + } + } + + dest_len = convert_string_allocate(ctx, + CH_DOS, + CH_UNIX, + src, + src_len, + &dest, + True); + + if (dest_len == (size_t)-1) { + return 0; + } + + if (dest_len && dest) { + /* Did we already process the terminating zero ? */ + if (dest[dest_len-1] != 0) { + dest[dest_len-1] = 0; + } + } else if (dest) { + dest[0] = 0; + } + + *ppdest = dest; + return src_len; +} + + size_t pull_ascii_pstring(char *dest, const void *src) { return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE); @@ -1214,7 +1298,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ /* ucs2 is always a multiple of 2 bytes */ if (src_len != (size_t)-1) src_len &= ~1; - + ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { return 0; @@ -1222,7 +1306,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (src_len == (size_t)-1) src_len = ret*2; - + if (dest_len && ret) { /* Did we already process the terminating zero ? */ if (dest[MIN(ret-1, dest_len-1)] != 0) { @@ -1235,6 +1319,92 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ return src_len; } +/** + Copy a string from a ucs2 source to a unix char* destination. + Talloc version with a base pointer. + Uses malloc if TALLOC_CTX is NULL (this is a bad interface and + needs fixing. JRA). + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_NOALIGN means don't try to align. + if STR_TERMINATE is set then src_len is ignored if it is -1. + src_len is the length of the source area in bytes + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. +**/ + +static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, + const void *base_ptr, + char **ppdest, + const void *src, + size_t src_len, + int flags) +{ + char *dest; + size_t dest_len; + + *ppdest = NULL; + +#ifdef DEVELOPER + /* Ensure we never use the braindead "malloc" varient. */ + if (ctx == NULL) { + smb_panic("NULL talloc CTX in pull_ucs2_base_talloc\n"); + } +#endif + + if (ucs2_align(base_ptr, src, flags)) { + src = (const void *)((const char *)src + 1); + if (src_len != (size_t)-1) + src_len--; + } + + if (flags & STR_TERMINATE) { + /* src_len -1 is the default for null terminated strings. */ + if (src_len != (size_t)-1) { + size_t len = strnlen_w((const smb_ucs2_t *)src, + src_len/2); + if (len < src_len/2) + len++; + src_len = len*2; + } + /* Ensure we don't use an insane length from the client. */ + if (src_len >= 1024*1024) { + smb_panic("Bad src length in pull_ucs2_base_talloc\n"); + } + } + + /* ucs2 is always a multiple of 2 bytes */ + if (src_len != (size_t)-1) { + src_len &= ~1; + } + + dest_len = convert_string_talloc(ctx, + CH_UTF16LE, + CH_UNIX, + src, + src_len, + (void **)&dest, + True); + if (dest_len == (size_t)-1) { + return 0; + } + + if (src_len == (size_t)-1) + src_len = dest_len*2; + + if (dest_len) { + /* Did we already process the terminating zero ? */ + if (dest[dest_len-1] != 0) { + dest[dest_len-1] = 0; + } + } else if (dest) { + dest[0] = 0; + } + + *ppdest = dest; + return src_len; +} + size_t pull_ucs2_pstring(char *dest, const void *src) { return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); @@ -1398,6 +1568,54 @@ size_t pull_string_fn(const char *function, unsigned int line, return pull_ascii(dest, src, dest_len, src_len, flags); } +/** + Copy a string from a unicode or ascii source (depending on + the packet flags) to a char* destination. + Variant that uses talloc. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_UNICODE means to force as unicode. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + if STR_TERMINATE is set then src_len is ignored is it is -1 + src_len is the length of the source area in bytes. + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. +**/ + +size_t pull_string_talloc_fn(const char *function, + unsigned int line, + TALLOC_CTX *ctx, + const void *base_ptr, + uint16 smb_flags2, + char **ppdest, + const void *src, + size_t src_len, + int flags) +{ + if ((base_ptr == NULL) && ((flags & (STR_ASCII|STR_UNICODE)) == 0)) { + smb_panic("No base ptr to get flg2 and neither ASCII nor " + "UNICODE defined"); + } + + if (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (smb_flags2 & FLAGS2_UNICODE_STRINGS)))) { + return pull_ucs2_base_talloc(ctx, + base_ptr, + ppdest, + src, + src_len, + flags); + } + return pull_ascii_base_talloc(ctx, + ppdest, + src, + src_len, + flags); +} + + size_t align_string(const void *base_ptr, const char *p, int flags) { if (!(flags & STR_ASCII) && \ -- cgit From 6eca5f5042c95f4532aac46e136a9bff5c45cbc2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 13 Jul 2007 11:36:55 +0000 Subject: r23865: Fix a type-punned error (This used to be commit a40d3a566af88464fc6afd2c6e6e8b6e3a98aac2) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b71e15f44d..30941dd7e8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1383,7 +1383,7 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, CH_UNIX, src, src_len, - (void **)&dest, + (void *)&dest, True); if (dest_len == (size_t)-1) { return 0; -- cgit From b62bd05b93e2317f78a4aea089295cf1162d23e2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 2 Aug 2007 18:06:45 +0000 Subject: r24133: Explicitly pass flags2 down to push_string_fn This needs a bit closer review, it also touches the client libs (This used to be commit 824eb26738d64af1798d319d339582cf047521f0) --- source3/lib/charcnv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 30941dd7e8..349fbff850 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1504,7 +1504,10 @@ size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) is -1 then no maxiumum is used. **/ -size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) +size_t push_string_fn(const char *function, unsigned int line, + const void *base_ptr, uint16 flags2, + void *dest, const char *src, + size_t dest_len, int flags) { #ifdef DEVELOPER /* We really need to zero fill here, not clobber @@ -1524,7 +1527,7 @@ size_t push_string_fn(const char *function, unsigned int line, const void *base_ if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ - (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { + (flags2 & FLAGS2_UNICODE_STRINGS)))) { return push_ucs2(base_ptr, dest, src, dest_len, flags); } return push_ascii(dest, src, dest_len, flags); -- cgit From 132ee3990af5d31573978f5a3abf43db2303880b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Sep 2007 20:57:01 +0000 Subject: r25009: Large patch discussed with Volker. Move unix_convert to a talloc-based interface. More development will come on top of this. Remove the "mangled map" parameter. Jeremy. (This used to be commit dee8beba7a92b8a3f68bbcc59fd0a827f68c7736) --- source3/lib/charcnv.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 349fbff850..dd03a56233 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -804,6 +804,71 @@ char *strdup_upper(const char *s) return SMB_STRDUP(out_buffer); } +/** + talloc_strdup() a unix string to upper case. +**/ + +char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) +{ + char *out_buffer = talloc_strdup(ctx,s); + const unsigned char *p = (const unsigned char *)s; + unsigned char *q = (unsigned char *)out_buffer; + + if (!q) { + return NULL; + } + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + + while (1) { + if (*p & 0x80) + break; + *q++ = toupper_ascii(*p); + if (!*p) + break; + p++; + } + + if (*p) { + /* MB case. */ + size_t size; + smb_ucs2_t *ubuf = NULL; + + /* We're not using the ascii buffer above. */ + TALLOC_FREE(out_buffer); + + size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, + s, strlen(s), + (void *)&ubuf, + True); + if (size == (size_t)-1) { + return NULL; + } + + strupper_w(ubuf); + + size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, + ubuf, size, + (void *)&out_buffer, + True); + + /* Don't need the intermediate buffer + * anymore. + */ + + TALLOC_FREE(ubuf); + + if (size == (size_t)-1) { + return NULL; + } + } + + return out_buffer; +} + size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; -- cgit From 3a9d3821649c9ea88a6cd424f0838a453165a00a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Sep 2007 23:57:59 +0000 Subject: r25111: Move to talloced pathnames on most code paths. There are now ony 17 pstrings left in reply.c, and these will be easy to remove (and I'll be doing that shortly). Had to fix an interesting bug in pull_ucs2_base_talloc() when a source string is not null terminated :-). Jeremy. (This used to be commit 0c9a8c4dff10974dbffd2a302ae982896122fcc0) --- source3/lib/charcnv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index dd03a56233..4e3b7cba62 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1460,7 +1460,21 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, if (dest_len) { /* Did we already process the terminating zero ? */ if (dest[dest_len-1] != 0) { - dest[dest_len-1] = 0; + size_t size = talloc_get_size(dest); + /* Have we got space to append the '\0' ? */ + if (size <= dest_len) { + /* No, realloc. */ + dest = TALLOC_REALLOC(ctx, dest, + dest_len+1); + if (!dest) { + /* talloc fail. */ + dest_len = (size_t)-1; + return 0; + } + } + /* Yay - space ! */ + dest[dest_len] = '\0'; + dest_len++; } } else if (dest) { dest[0] = 0; -- cgit From 12f61e09d943ea7fc4149166077507b5b0b3b4e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Sep 2007 21:48:20 +0000 Subject: r25117: The mega-patch Jerry was waiting for. Remove all pstrings from the main server code paths. We should now be able to cope with paths up to PATH_MAX length now. Final job will be to add the TALLOC_CTX * parameter to unix_convert to make it explicit (for Volker). Jeremy. (This used to be commit 7f0db75fb0f24873577dcb758a2ecee74fdc4297) --- source3/lib/charcnv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4e3b7cba62..5e265234e6 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1106,7 +1106,11 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, } /* Ensure we don't use an insane length from the client. */ if (src_len >= 1024*1024) { - smb_panic("Bad src length in pull_ascii_base_talloc\n"); + char *msg = talloc_asprintf(ctx, + "Bad src length (%u) in " + "pull_ascii_base_talloc", + src_len); + smb_panic(msg); } } -- cgit From 6716382ec9aa606ef6975ae24cf699bfc69537e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Sep 2007 00:31:02 +0000 Subject: r25120: One more warning. Jeremy. (This used to be commit 9cc70e3ccff9c3b20076572235d9dcbfd23e97e5) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 5e265234e6..4a2e768d05 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1109,7 +1109,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, char *msg = talloc_asprintf(ctx, "Bad src length (%u) in " "pull_ascii_base_talloc", - src_len); + (unsigned int)src_len); smb_panic(msg); } } -- cgit From d0de93ca762e8b59f09c2179448188c9952f68fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Sep 2007 17:25:57 +0000 Subject: r25136: When tallocing a string to uppercase remember the terminating '\0' in size calculations. Jeremy. (This used to be commit 54c658867db3b6c602080d60936abab3af26e112) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 4a2e768d05..c481c9a7e2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -841,7 +841,7 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) TALLOC_FREE(out_buffer); size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, - s, strlen(s), + s, strlen(s)+1, (void *)&ubuf, True); if (size == (size_t)-1) { -- cgit From eacd3140573d1122a3785823e4003bfc6352c431 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Sep 2007 22:08:59 +0000 Subject: r25138: More pstring elimination. Add a TALLOC_CTX parameter to unix_convert(). Jeremy. (This used to be commit 39c211a702e91c34c1a5a689e1b0c4530ea8a1ac) --- source3/lib/charcnv.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c481c9a7e2..26581ba305 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -935,27 +935,40 @@ static size_t ucs2_align(const void *base_ptr, const void *p, int flags) * * * @param dest_len the maximum length in bytes allowed in the - * destination. If @p dest_len is -1 then no maximum is used. + * destination. **/ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); - pstring tmpbuf; + char *tmpbuf = NULL; + size_t ret; - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + /* No longer allow a length of -1. */ + if (dest_len == (size_t)-1) { + smb_panic("push_ascii - dest_len == -1"); + return (size_t)0; + } if (flags & STR_UPPER) { - pstrcpy(tmpbuf, src); + tmpbuf = SMB_STRDUP(src); + if (!tmpbuf) { + smb_panic("malloc fail"); + return (size_t)0; + } strupper_m(tmpbuf); src = tmpbuf; } - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { src_len++; + } - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + SAFE_FREE(tmpbuf); + if (ret == (size_t)-1) { + return 0; + } + return ret; } size_t push_ascii_fstring(void *dest, const char *src) @@ -1007,6 +1020,18 @@ size_t push_ascii_nstring(void *dest, const char *src) return dest_len; } +/******************************************************************** + Push and malloc an ascii string. src and dest null terminated. +********************************************************************/ + +size_t push_ascii_allocate(char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, (void **)dest, True); +} + /** * Copy a string from a dos codepage source to a unix char* destination. * -- cgit From ad97bcf813d5f06df4711896eefc99c0c32651cc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Sep 2007 20:24:35 +0000 Subject: r25184: Fix some C++ warnings and an uninitialized variable (This used to be commit b64df8a3c504ab7749c21ffb26e4771a9a0a328f) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 26581ba305..a8fb95df06 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1493,7 +1493,7 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, /* Have we got space to append the '\0' ? */ if (size <= dest_len) { /* No, realloc. */ - dest = TALLOC_REALLOC(ctx, dest, + dest = TALLOC_REALLOC_ARRAY(ctx, dest, char, dest_len+1); if (!dest) { /* talloc fail. */ -- cgit From 4f051e735b85a24f37e2b844bcbb348f36600420 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Sep 2007 10:50:59 +0000 Subject: r25195: Fix issue with calling pull_uc2_*alloc with str_len == 0. We should just return 0 in this case. Jeremy. (This used to be commit 8bb85f3f141f0f45b06d28f004cb2cf18252d4e1) --- source3/lib/charcnv.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a8fb95df06..9e669a1c9c 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1369,6 +1369,10 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ { size_t ret; + if (!src_len) { + return 0; + } + if (dest_len == (size_t)-1) dest_len = sizeof(pstring); @@ -1446,6 +1450,10 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, } #endif + if (!src_len) { + return 0; + } + if (ucs2_align(base_ptr, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len != (size_t)-1) -- cgit From 38ffbd2893ceac2a45cef3694364c34262ef5fa9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Sep 2007 19:43:06 +0000 Subject: r25199: Remove pstring from strdup_upper - make it the same as talloc_strdup_upper. Jeremy. (This used to be commit db1b6293771755f20660b071aac0284638dbed46) --- source3/lib/charcnv.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9e669a1c9c..26c50c1391 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -759,49 +759,68 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) /** strdup() a unix string to upper case. - Max size is pstring. **/ char *strdup_upper(const char *s) { - pstring out_buffer; + char *out_buffer = SMB_STRDUP(s); const unsigned char *p = (const unsigned char *)s; unsigned char *q = (unsigned char *)out_buffer; + if (!q) { + return NULL; + } + /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our supported multi-byte character sets are ascii-compatible (ie. they match for the first 128 chars) */ - while (1) { + while (*p) { if (*p & 0x80) break; *q++ = toupper_ascii(*p); - if (!*p) - break; p++; - if (p - ( const unsigned char *)s >= sizeof(pstring)) - break; } if (*p) { /* MB case. */ size_t size; - wpstring buffer; - size = convert_string(CH_UNIX, CH_UTF16LE, s, -1, buffer, sizeof(buffer), True); + smb_ucs2_t *buffer = NULL; + + SAFE_FREE(out_buffer); + size = convert_string_allocate(NULL, + CH_UNIX, + CH_UTF16LE, + s, + strlen(s) + 1, + (void **)(void *)&buffer, + True); if (size == (size_t)-1) { return NULL; } strupper_w(buffer); - size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); + size = convert_string_allocate(NULL, + CH_UTF16LE, + CH_UNIX, + buffer, + size, + (void **)(void *)&out_buffer, + True); + + /* Don't need the intermediate buffer + * anymore. + */ + + TALLOC_FREE(buffer); if (size == (size_t)-1) { return NULL; } } - return SMB_STRDUP(out_buffer); + return out_buffer; } /** @@ -823,12 +842,10 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) supported multi-byte character sets are ascii-compatible (ie. they match for the first 128 chars) */ - while (1) { + while (*p) { if (*p & 0x80) break; *q++ = toupper_ascii(*p); - if (!*p) - break; p++; } -- cgit From 3d5f029ead8ccea45a5537a51f24c5144102a29b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Sep 2007 09:40:40 +0000 Subject: r25222: Fix last assumptions that (size_t)-1 can be used as a special dest_len of sizeof(pstring). Jeremy. (This used to be commit 9fc14c83cc5e3a360464c33e26b1073db63763d7) --- source3/lib/charcnv.c | 54 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 26c50c1391..3f9beb0254 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -745,7 +745,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size = push_ucs2_allocate(&buffer, src); if (size == (size_t)-1) { - smb_panic("failed to create UCS2 buffer"); + return 0; } if (!strupper_w(buffer) && (dest == src)) { free(buffer); @@ -1068,8 +1068,11 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, { size_t ret; - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + if (dest_len == (size_t)-1) { + /* No longer allow dest_len of -1. */ + smb_panic("pull_ascii - invalid dest_len of -1"); + return 0; + } if (flags & STR_TERMINATE) { if (src_len == (size_t)-1) { @@ -1213,7 +1216,7 @@ size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src) * * * @param dest_len is the maximum length allowed in the - * destination. If dest_len is -1 then no maxiumum is used. + * destination. **/ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) @@ -1222,9 +1225,11 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ size_t src_len; size_t ret; - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + if (dest_len == (size_t)-1) { + /* No longer allow dest_len of -1. */ + smb_panic("push_ucs2 - invalid dest_len of -1"); + return 0; + } if (flags & STR_TERMINATE) src_len = (size_t)-1; @@ -1315,23 +1320,33 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) { - size_t src_len = strlen(src); - pstring tmpbuf; + size_t src_len = 0; + size_t ret; + char *tmpbuf = NULL; - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + if (dest_len == (size_t)-1) { + /* No longer allow dest_len of -1. */ + smb_panic("push_utf8 - invalid dest_len of -1"); + return 0; + } if (flags & STR_UPPER) { - pstrcpy(tmpbuf, src); - strupper_m(tmpbuf); + tmpbuf = strdup_upper(src); + if (!tmpbuf) { + return 0; + } src = tmpbuf; + src_len = strlen(src); } - if (flags & STR_TERMINATE) + src_len = strlen(src); + if (flags & STR_TERMINATE) { src_len++; + } - return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len, True); + SAFE_FREE(tmpbuf); + return ret; } size_t push_utf8_fstring(void *dest, const char *src) @@ -1390,8 +1405,11 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ return 0; } - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + if (dest_len == (size_t)-1) { + /* No longer allow dest_len of -1. */ + smb_panic("push_utf8 - invalid dest_len of -1"); + return 0; + } if (ucs2_align(base_ptr, src, flags)) { src = (const void *)((const char *)src + 1); -- cgit From 934b92f5d0e4950f7b4c7531eecf3df59a4d0ed3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Sep 2007 17:52:06 +0000 Subject: r25238: Make the error returns from the string functions always consistent. Return -1 on error, and ensure we check for this. In cases where the dest is already specified and we've been asked to terminate with a null, ensure we always do so even on error. Jeremy. (This used to be commit abedd967869ade9a43c3a8e1b889c60d4aca81cf) --- source3/lib/charcnv.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 3f9beb0254..c3493dc9dc 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -745,7 +745,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size = push_ucs2_allocate(&buffer, src); if (size == (size_t)-1) { - return 0; + return (size_t)-1; } if (!strupper_w(buffer) && (dest == src)) { free(buffer); @@ -963,14 +963,12 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) /* No longer allow a length of -1. */ if (dest_len == (size_t)-1) { smb_panic("push_ascii - dest_len == -1"); - return (size_t)0; } if (flags & STR_UPPER) { tmpbuf = SMB_STRDUP(src); if (!tmpbuf) { smb_panic("malloc fail"); - return (size_t)0; } strupper_m(tmpbuf); src = tmpbuf; @@ -981,10 +979,12 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) } ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); - SAFE_FREE(tmpbuf); - if (ret == (size_t)-1) { - return 0; + if (ret == (size_t)-1 && + (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + && dest_len > 0) { + ((char *)dest)[0] = '\0'; } + SAFE_FREE(tmpbuf); return ret; } @@ -1071,7 +1071,6 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (dest_len == (size_t)-1) { /* No longer allow dest_len of -1. */ smb_panic("pull_ascii - invalid dest_len of -1"); - return 0; } if (flags & STR_TERMINATE) { @@ -1168,7 +1167,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, True); if (dest_len == (size_t)-1) { - return 0; + dest_len = 0; } if (dest_len && dest) { @@ -1228,7 +1227,6 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ if (dest_len == (size_t)-1) { /* No longer allow dest_len of -1. */ smb_panic("push_ucs2 - invalid dest_len of -1"); - return 0; } if (flags & STR_TERMINATE) @@ -1249,7 +1247,12 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { - return 0; + if ((flags & STR_TERMINATE) && + dest && + dest_len) { + *(char *)dest = 0; + } + return len; } len += ret; @@ -1327,13 +1330,12 @@ static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) if (dest_len == (size_t)-1) { /* No longer allow dest_len of -1. */ smb_panic("push_utf8 - invalid dest_len of -1"); - return 0; } if (flags & STR_UPPER) { tmpbuf = strdup_upper(src); if (!tmpbuf) { - return 0; + return (size_t)-1; } src = tmpbuf; src_len = strlen(src); @@ -1434,7 +1436,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True); if (ret == (size_t)-1) { - return 0; + ret = 0; + dest_len = 0; } if (src_len == (size_t)-1) @@ -1523,7 +1526,7 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, (void *)&dest, True); if (dest_len == (size_t)-1) { - return 0; + dest_len = 0; } if (src_len == (size_t)-1) @@ -1668,11 +1671,9 @@ size_t push_string_fn(const char *function, unsigned int line, * JRA. */ #if 0 - if (dest_len != (size_t)-1) - clobber_region(function, line, dest, dest_len); + clobber_region(function, line, dest, dest_len); #else - if (dest_len != (size_t)-1) - memset(dest, '\0', dest_len); + memset(dest, '\0', dest_len); #endif #endif @@ -1705,8 +1706,7 @@ size_t pull_string_fn(const char *function, unsigned int line, int flags) { #ifdef DEVELOPER - if (dest_len != (size_t)-1) - clobber_region(function, line, dest, dest_len); + clobber_region(function, line, dest, dest_len); #endif if ((base_ptr == NULL) && ((flags & (STR_ASCII|STR_UNICODE)) == 0)) { -- cgit From 2bb7ebdcb737fa621f8935680d28504f1ea38252 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Sep 2007 12:42:15 +0000 Subject: r25258: Fix a panic message and remove superfluous return after the call to smb_panic(). Michael (This used to be commit 8b5c34b7d141c44d65622f44f9432723230cea47) --- source3/lib/charcnv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c3493dc9dc..f6b9e06ec2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1409,8 +1409,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (dest_len == (size_t)-1) { /* No longer allow dest_len of -1. */ - smb_panic("push_utf8 - invalid dest_len of -1"); - return 0; + smb_panic("pull_ucs2 - invalid dest_len of -1"); } if (ucs2_align(base_ptr, src, flags)) { -- cgit From 3f2939cc167cca2e7f5758f231b470507c600360 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 21 Sep 2007 10:32:57 +0000 Subject: r25277: Belt-and-braces approach to Volker's fix for RPC-SAMBA3-GETUSERNAME. If we promise dest is null terminated, ensure we do it even on fast path exits. Jeremy. (This used to be commit 32626e2b9770eb6b15c191a8feb881f81ed6c57a) --- source3/lib/charcnv.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index f6b9e06ec2..b1e3d3bdcf 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1403,15 +1403,18 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ { size_t ret; - if (!src_len) { - return 0; - } - if (dest_len == (size_t)-1) { /* No longer allow dest_len of -1. */ smb_panic("pull_ucs2 - invalid dest_len of -1"); } + if (!src_len) { + if (dest && dest_len > 0) { + dest[0] = '\0'; + } + return 0; + } + if (ucs2_align(base_ptr, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len != (size_t)-1) -- 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/charcnv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b1e3d3bdcf..7c3545dab1 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -46,7 +46,7 @@ char lp_failed_convert_char(void) static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */ +static bool conv_silent; /* Should we do a debug if the conversion fails ? */ /** * Return the name of a charset to give to iconv(). @@ -128,7 +128,7 @@ void gfree_charcnv(void) void init_iconv(void) { int c1, c2; - BOOL did_reload = False; + bool did_reload = False; /* so that charset_name() works we need to get the UNIX<->UCS2 going first */ @@ -201,7 +201,7 @@ void init_iconv(void) static size_t convert_string_internal(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen, BOOL allow_bad_conv) + void *dest, size_t destlen, bool allow_bad_conv) { size_t i_len, o_len; size_t retval; @@ -375,7 +375,7 @@ static size_t convert_string_internal(charset_t from, charset_t to, size_t convert_string(charset_t from, charset_t to, void const *src, size_t srclen, - void *dest, size_t destlen, BOOL allow_bad_conv) + void *dest, size_t destlen, bool allow_bad_conv) { /* * NB. We deliberately don't do a strlen here if srclen == -1. @@ -523,7 +523,7 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, BOOL allow_bad_conv) + void const *src, size_t srclen, void *dst, bool allow_bad_conv) { size_t i_len, o_len, destlen = MAX(srclen, 512); size_t retval; @@ -724,7 +724,7 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, **/ size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, - BOOL allow_bad_conv) + bool allow_bad_conv) { void **dest = (void **)dst; size_t dest_len; -- cgit From cf31bb7532484dbe26e4a00506ade0a173d8d754 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Nov 2007 17:51:21 -0800 Subject: Start to remove some of the pstring functions we're no longer using. Jeremy. (This used to be commit c21e9bdc1059268adbd14207e74097349676439e) --- source3/lib/charcnv.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7c3545dab1..da972f550f 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -993,11 +993,6 @@ size_t push_ascii_fstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(fstring), STR_TERMINATE); } -size_t push_ascii_pstring(void *dest, const char *src) -{ - return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); -} - /******************************************************************** Push an nstring - ensure null terminated. Written by moriyama@miraclelinux.com (MORIYAMA Masayuki). @@ -1471,7 +1466,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ The resulting string in "dest" is always null terminated. **/ -static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, +size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, const void *base_ptr, char **ppdest, const void *src, @@ -1561,11 +1556,6 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, return src_len; } -size_t pull_ucs2_pstring(char *dest, const void *src) -{ - return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE); -} - size_t pull_ucs2_fstring(char *dest, const void *src) { return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE); -- cgit From c049b8157d0bb4b5cd57b66740a26813be4f9eba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Nov 2007 15:31:37 -0800 Subject: More trivial pstring removal. Jeremy. (This used to be commit bac3bb2f6e9e15b3a9a6a6511c484f8509918ca1) --- source3/lib/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index da972f550f..0dfa88e87e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -932,7 +932,7 @@ char *strdup_lower(const char *s) return out_buffer; } -static size_t ucs2_align(const void *base_ptr, const void *p, int flags) +size_t ucs2_align(const void *base_ptr, const void *p, int flags) { if (flags & (STR_NOALIGN|STR_ASCII)) return 0; -- cgit From 5ea101f048483899d4a0a36c7eb6e768e408feec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 4 Dec 2007 15:21:14 -0800 Subject: Allow STR_TERMINATE and -1 src_len for pull_ucs2_base_talloc(). Jeremy. (This used to be commit 063358d87ac9a1d948c8d4b6358e926dd14bb3ac) --- source3/lib/charcnv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0dfa88e87e..9592bbc287 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -592,7 +592,7 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, goto use_as_is; break; case E2BIG: - goto convert; + goto convert; case EILSEQ: reason="Illegal multibyte sequence"; if (!conv_silent) @@ -1503,6 +1503,12 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, if (len < src_len/2) len++; src_len = len*2; + } else { + /* + * src_len == -1 - alloc interface won't take this + * so we must calculate. + */ + src_len = (strlen_w((const smb_ucs2_t *)src)+1)*sizeof(smb_ucs2_t); } /* Ensure we don't use an insane length from the client. */ if (src_len >= 1024*1024) { -- cgit From 755051b569762c13f8f4b4e52fa1183108a4e466 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 4 Dec 2007 17:05:33 -0800 Subject: pull_ascii_pstring is gone. Jeremy. (This used to be commit 288aacce4b56d159218be311019cb951e5a232fd) --- source3/lib/charcnv.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9592bbc287..ed778ad5e2 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1178,12 +1178,6 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, return src_len; } - -size_t pull_ascii_pstring(char *dest, const void *src) -{ - return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE); -} - size_t pull_ascii_fstring(char *dest, const void *src) { return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); -- cgit From 1b92ea5559bfa00016103508feac9a06ea4b66ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 17:16:33 -0800 Subject: Remove pstrings from client/client.c by doing a large rewrite. Mostly compiles.... Jeremy. (This used to be commit c87f3eba9aa52f4ab25d77e2167262bf5c43b1a6) --- source3/lib/charcnv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index ed778ad5e2..2515e6cef3 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1692,10 +1692,15 @@ size_t push_string_fn(const char *function, unsigned int line, The resulting string in "dest" is always null terminated. **/ -size_t pull_string_fn(const char *function, unsigned int line, - const void *base_ptr, uint16 smb_flags2, char *dest, - const void *src, size_t dest_len, size_t src_len, - int flags) +size_t pull_string_fn(const char *function, + unsigned int line, + const void *base_ptr, + uint16 smb_flags2, + char *dest, + const void *src, + size_t dest_len, + size_t src_len, + int flags) { #ifdef DEVELOPER clobber_region(function, line, dest, dest_len); -- cgit From 2ae400b213a673253da0e3088ce1c3f54d9681cc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 16 Dec 2007 00:17:41 +0100 Subject: Make init_doschar_table() static It's only called directly before init_valid_table() anyway, so move it there. (This used to be commit b6d1d2428866712a550a354732e2386b4f87b67b) --- source3/lib/charcnv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 2515e6cef3..8a00b235cc 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -178,7 +178,6 @@ void init_iconv(void) * codepage changes? */ /* XXX: Is the did_reload test too strict? */ conv_silent = True; - init_doschar_table(); init_valid_table(); conv_silent = False; } -- cgit From 980ac0984905d8c3f29dd62ed75fc9c7cb22cdd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jan 2008 17:32:26 -0800 Subject: Fixup hot paths - add macro for toupper (c < 0x80). This now matches 3.0.x on my micro-tests. Jeremy. (This used to be commit 329b924cba8225002ca40db26c45b31d141a0925) --- source3/lib/charcnv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 8a00b235cc..eeff805459 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -614,10 +614,16 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, out: destlen = destlen - o_len; - if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); - } else { - ob = (char *)SMB_REALLOC(ob,destlen); + /* Don't shrink unless we're reclaiming a lot of + * space. This is in the hot codepath and these + * reallocs *cost*. JRA. + */ + if (o_len > 1024) { + if (ctx) { + ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); + } else { + ob = (char *)SMB_REALLOC(ob,destlen); + } } if (destlen && !ob) { @@ -778,7 +784,7 @@ char *strdup_upper(const char *s) while (*p) { if (*p & 0x80) break; - *q++ = toupper_ascii(*p); + *q++ = toupper_ascii_fast(*p); p++; } @@ -844,7 +850,7 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) while (*p) { if (*p & 0x80) break; - *q++ = toupper_ascii(*p); + *q++ = toupper_ascii_fast(*p); p++; } -- cgit From b9b75f37acec632333cea1737edc46071661b480 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Feb 2008 14:23:54 -0800 Subject: Ensure that convert_string_allocate() allocates 2 extra bytes and null terminates them to ensure NDR wire-reads of string types are always null terminated. Bug found by Volker after great pain :-). Jeremy. (This used to be commit aab736e6079729b3f3ab653674834e3f1305d456) --- source3/lib/charcnv.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index eeff805459..d11620ecd7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -524,7 +524,7 @@ size_t convert_string(charset_t from, charset_t to, size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, bool allow_bad_conv) { - size_t i_len, o_len, destlen = MAX(srclen, 512); + size_t i_len, o_len, destlen = (srclen * 3) / 2; size_t retval; const char *inbuf = (const char *)src; char *outbuf = NULL, *ob = NULL; @@ -550,7 +550,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, convert: - if ((destlen*2) < destlen) { + /* +2 is for ucs2 null termination. */ + if ((destlen*2)+2 < destlen) { /* wrapped ! abort. */ if (!conv_silent) DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); @@ -561,10 +562,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, destlen = destlen * 2; } + /* +2 is for ucs2 null termination. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); + ob = (char *)TALLOC_REALLOC(ctx, ob, destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob, destlen); + ob = (char *)SMB_REALLOC(ob, destlen + 2); } if (!ob) { @@ -619,10 +621,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * reallocs *cost*. JRA. */ if (o_len > 1024) { + /* We're shrinking here so we know the +2 is safe from wrap. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); + ob = (char *)TALLOC_REALLOC(ctx,ob,destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob,destlen); + ob = (char *)SMB_REALLOC(ob,destlen + 2); } } @@ -632,6 +635,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } *dest = ob; + + /* Must ucs2 null terminate in the extra space we allocated. */ + ob[destlen] = '\0'; + ob[destlen+1] = '\0'; + return destlen; use_as_is: -- cgit From 1fcbcbb486e7c599b11872f003ae213610ea09e4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Apr 2008 15:36:55 +0200 Subject: charcnv: add talloc_strdup_lower() - talloc variant of strdup_lower(). Michael (This used to be commit 5f6c730cbeddd1ac2f515bd985c08ceb4ca9bc47) --- source3/lib/charcnv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d11620ecd7..69d1db0e48 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -945,6 +945,32 @@ char *strdup_lower(const char *s) return out_buffer; } +char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s) +{ + size_t size; + smb_ucs2_t *buffer = NULL; + char *out_buffer; + + size = push_ucs2_talloc(ctx, &buffer, s); + if (size == -1 || !buffer) { + TALLOC_FREE(buffer); + return NULL; + } + + strlower_w(buffer); + + size = pull_ucs2_talloc(ctx, &out_buffer, buffer); + TALLOC_FREE(buffer); + + if (size == (size_t)-1) { + TALLOC_FREE(out_buffer); + return NULL; + } + + return out_buffer; +} + + size_t ucs2_align(const void *base_ptr, const void *p, int flags) { if (flags & (STR_NOALIGN|STR_ASCII)) -- cgit From bb869741ddc3d82da02c96bef592dab6074ff142 Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Mon, 3 Mar 2008 13:32:54 -0800 Subject: Cleanup size_t return values in convert_string_allocate This patch is the first iteration of an inside-out conversion to cleanup functions in charcnv.c returning size_t == -1 to indicate failure. (This used to be commit 59124382d2894a1b194b48dd82bc5f956959eb48) --- source3/lib/charcnv.c | 134 ++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 58 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 69d1db0e48..81b7238763 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -511,9 +511,12 @@ size_t convert_string(charset_t from, charset_t to, * (this is a bad interface and needs fixing. JRA). * @param srclen length of source buffer. * @param dest always set at least to NULL + * @param converted_size set to the size of the allocated buffer on return + * true * @note -1 is not accepted for srclen. * - * @returns Size in bytes of the converted string; or -1 in case of error. + * @return True if new buffer was correctly allocated, and string was + * converted. * * Ensure the srclen contains the terminating zero. * @@ -521,8 +524,9 @@ size_t convert_string(charset_t from, charset_t to, * There has to be a cleaner way to do this. JRA. **/ -size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, bool allow_bad_conv) +bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + size_t *converted_size, bool allow_bad_conv) { size_t i_len, o_len, destlen = (srclen * 3) / 2; size_t retval; @@ -533,10 +537,19 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, *dest = NULL; - if (src == NULL || srclen == (size_t)-1) - return (size_t)-1; - if (srclen == 0) - return 0; + if (!converted_size) { + errno = EINVAL; + return false; + } + + if (src == NULL || srclen == (size_t)-1) { + errno = EINVAL; + return false; + } + if (srclen == 0) { + *converted_size = 0; + return true; + } lazy_initialize_conv(); @@ -545,7 +558,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { if (!conv_silent) DEBUG(0,("convert_string_allocate: Conversion not supported.\n")); - return (size_t)-1; + errno = EOPNOTSUPP; + return false; } convert: @@ -557,7 +571,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); if (!ctx) SAFE_FREE(outbuf); - return (size_t)-1; + errno = EOPNOTSUPP; + return false; } else { destlen = destlen * 2; } @@ -571,7 +586,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); - return (size_t)-1; + errno = ENOMEM; + return false; } outbuf = ob; i_len = srclen; @@ -610,7 +626,7 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } else { SAFE_FREE(ob); } - return (size_t)-1; + return false; } out: @@ -631,7 +647,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, if (destlen && !ob) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); - return (size_t)-1; + errno = ENOMEM; + return false; } *dest = ob; @@ -640,7 +657,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, ob[destlen] = '\0'; ob[destlen+1] = '\0'; - return destlen; + *converted_size = destlen; + return true; use_as_is: @@ -743,8 +761,8 @@ size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, size_t dest_len; *dest = NULL; - dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest, allow_bad_conv); - if (dest_len == (size_t)-1) + if (!convert_string_allocate(ctx, from, to, src, srclen, dest, + &dest_len, allow_bad_conv)) return (size_t)-1; if (*dest == NULL) return (size_t)-1; @@ -798,39 +816,28 @@ char *strdup_upper(const char *s) if (*p) { /* MB case. */ - size_t size; + size_t size, size2; smb_ucs2_t *buffer = NULL; SAFE_FREE(out_buffer); - size = convert_string_allocate(NULL, - CH_UNIX, - CH_UTF16LE, - s, - strlen(s) + 1, - (void **)(void *)&buffer, - True); - if (size == (size_t)-1) { + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, s, + strlen(s) + 1, (void **)(void *)&buffer, &size, + True)) { return NULL; } strupper_w(buffer); - size = convert_string_allocate(NULL, - CH_UTF16LE, - CH_UNIX, - buffer, - size, - (void **)(void *)&out_buffer, - True); + if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer, + size, (void **)(void *)&out_buffer, &size2, True)) { + TALLOC_FREE(buffer); + return NULL; + } /* Don't need the intermediate buffer * anymore. */ - TALLOC_FREE(buffer); - if (size == (size_t)-1) { - return NULL; - } } return out_buffer; @@ -904,9 +911,8 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer = NULL; - size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, - (void **)(void *)&buffer, True); - if (size == (size_t)-1 || !buffer) { + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, + (void **)(void *)&buffer, &size, True)) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { @@ -1077,10 +1083,14 @@ size_t push_ascii_nstring(void *dest, const char *src) size_t push_ascii_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, (void **)dest, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1192,17 +1202,9 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, } } - dest_len = convert_string_allocate(ctx, - CH_DOS, - CH_UNIX, - src, - src_len, - &dest, - True); - - if (dest_len == (size_t)-1) { + if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest, + &dest_len, True)) dest_len = 0; - } if (dest_len && dest) { /* Did we already process the terminating zero ? */ @@ -1333,10 +1335,14 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1410,10 +1416,14 @@ size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) size_t push_utf8_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, True); + if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1625,9 +1635,13 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) { - size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + size_t dest_len, src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); *dest = NULL; - return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); + if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** @@ -1655,9 +1669,13 @@ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) size_t pull_utf8_allocate(char **dest, const char *src) { - size_t src_len = strlen(src)+1; + size_t dest_len, src_len = strlen(src)+1; *dest = NULL; - return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); + if (!convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, &dest_len, True)) + return (size_t)-1; + else + return dest_len; } /** -- cgit From fb37f156009611af0dd454a0fb0829a09cd638ac Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Tue, 29 Apr 2008 14:36:24 -0700 Subject: Cleanup size_t return values in callers of convert_string_allocate This patch is the second iteration of an inside-out conversion to cleanup functions in charcnv.c returning size_t == -1 to indicate failure. (This used to be commit 6b189dabc562d86dcaa685419d0cb6ea276f100d) --- source3/lib/charcnv.c | 267 +++++++++++++++++++++++++++----------------------- 1 file changed, 143 insertions(+), 124 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 81b7238763..b1a5393461 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -515,7 +515,7 @@ size_t convert_string(charset_t from, charset_t to, * true * @note -1 is not accepted for srclen. * - * @return True if new buffer was correctly allocated, and string was + * @return true if new buffer was correctly allocated, and string was * converted. * * Ensure the srclen contains the terminating zero. @@ -749,24 +749,22 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * * @param srclen length of source buffer. * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * @note -1 is not accepted for srclen. * - * @returns Size in bytes of the converted string; or -1 in case of error. - **/ -size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void *dst, - bool allow_bad_conv) + * @return true if new buffer was correctly allocated, and string was + * converted. + */ +bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + size_t *converted_size, bool allow_bad_conv) { void **dest = (void **)dst; - size_t dest_len; *dest = NULL; - if (!convert_string_allocate(ctx, from, to, src, srclen, dest, - &dest_len, allow_bad_conv)) - return (size_t)-1; - if (*dest == NULL) - return (size_t)-1; - return dest_len; + return convert_string_allocate(ctx, from, to, src, srclen, dest, + converted_size, allow_bad_conv); } size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) @@ -774,10 +772,10 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) size_t size; smb_ucs2_t *buffer; - size = push_ucs2_allocate(&buffer, src); - if (size == (size_t)-1) { + if (!push_ucs2_allocate(&buffer, src, &size)) { return (size_t)-1; } + if (!strupper_w(buffer) && (dest == src)) { free(buffer); return srclen; @@ -816,20 +814,25 @@ char *strdup_upper(const char *s) if (*p) { /* MB case. */ - size_t size, size2; + size_t converted_size, converted_size2; smb_ucs2_t *buffer = NULL; SAFE_FREE(out_buffer); if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, s, - strlen(s) + 1, (void **)(void *)&buffer, &size, - True)) { + strlen(s) + 1, + (void **)(void *)&buffer, + &converted_size, True)) + { return NULL; } strupper_w(buffer); if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, buffer, - size, (void **)(void *)&out_buffer, &size2, True)) { + converted_size, + (void **)(void *)&out_buffer, + &converted_size2, True)) + { TALLOC_FREE(buffer); return NULL; } @@ -871,36 +874,33 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s) if (*p) { /* MB case. */ - size_t size; + size_t converted_size, converted_size2; smb_ucs2_t *ubuf = NULL; /* We're not using the ascii buffer above. */ TALLOC_FREE(out_buffer); - size = convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, - s, strlen(s)+1, - (void *)&ubuf, - True); - if (size == (size_t)-1) { + if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s, + strlen(s)+1, (void *)&ubuf, + &converted_size, True)) + { return NULL; } strupper_w(ubuf); - size = convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, - ubuf, size, - (void *)&out_buffer, - True); + if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, ubuf, + converted_size, (void *)&out_buffer, + &converted_size2, True)) + { + TALLOC_FREE(ubuf); + return NULL; + } /* Don't need the intermediate buffer * anymore. */ - TALLOC_FREE(ubuf); - - if (size == (size_t)-1) { - return NULL; - } } return out_buffer; @@ -912,7 +912,9 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, - (void **)(void *)&buffer, &size, True)) { + (void **)(void *)&buffer, &size, + True)) + { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { @@ -930,49 +932,45 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_lower(const char *s) { - size_t size; + size_t converted_size; smb_ucs2_t *buffer = NULL; char *out_buffer; - size = push_ucs2_allocate(&buffer, s); - if (size == -1 || !buffer) { + if (!push_ucs2_allocate(&buffer, s, &converted_size)) { return NULL; } strlower_w(buffer); - size = pull_ucs2_allocate(&out_buffer, buffer); - SAFE_FREE(buffer); - - if (size == (size_t)-1) { + if (!pull_ucs2_allocate(&out_buffer, buffer, &converted_size)) { + SAFE_FREE(buffer); return NULL; } + SAFE_FREE(buffer); + return out_buffer; } char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s) { - size_t size; + size_t converted_size; smb_ucs2_t *buffer = NULL; char *out_buffer; - size = push_ucs2_talloc(ctx, &buffer, s); - if (size == -1 || !buffer) { - TALLOC_FREE(buffer); + if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) { return NULL; } strlower_w(buffer); - size = pull_ucs2_talloc(ctx, &out_buffer, buffer); - TALLOC_FREE(buffer); - - if (size == (size_t)-1) { - TALLOC_FREE(out_buffer); + if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) { + TALLOC_FREE(buffer); return NULL; } + TALLOC_FREE(buffer); + return out_buffer; } @@ -1049,8 +1047,7 @@ size_t push_ascii_nstring(void *dest, const char *src) smb_ucs2_t *buffer; conv_silent = True; - buffer_len = push_ucs2_allocate(&buffer, src); - if (buffer_len == (size_t)-1) { + if (!push_ucs2_allocate(&buffer, src, &buffer_len)) { smb_panic("failed to create UCS2 buffer"); } @@ -1081,16 +1078,13 @@ size_t push_ascii_nstring(void *dest, const char *src) Push and malloc an ascii string. src and dest null terminated. ********************************************************************/ -size_t push_ascii_allocate(char **dest, const char *src) +bool push_ascii_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1172,7 +1166,7 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, int flags) { char *dest = NULL; - size_t dest_len = 0; + size_t converted_size; #ifdef DEVELOPER /* Ensure we never use the braindead "malloc" varient. */ @@ -1203,13 +1197,15 @@ static size_t pull_ascii_base_talloc(TALLOC_CTX *ctx, } if (!convert_string_allocate(ctx, CH_DOS, CH_UNIX, src, src_len, &dest, - &dest_len, True)) - dest_len = 0; + &converted_size, True)) + { + converted_size = 0; + } - if (dest_len && dest) { + if (converted_size && dest) { /* Did we already process the terminating zero ? */ - if (dest[dest_len-1] != 0) { - dest[dest_len-1] = 0; + if (dest[converted_size - 1] != 0) { + dest[converted_size - 1] = 0; } } else if (dest) { dest[0] = 0; @@ -1311,16 +1307,20 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ * allocating a buffer using talloc(). * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) +bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, converted_size, True); } @@ -1328,21 +1328,21 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination - * or -1 in case of error. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) +bool push_ucs2_allocate(smb_ucs2_t **dest, const char *src, + size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1394,36 +1394,41 @@ size_t push_utf8_fstring(void *dest, const char *src) * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True); + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, + (void**)dest, converted_size, True); } /** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t push_utf8_allocate(char **dest, const char *src) +bool push_utf8_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; *dest = NULL; - if (!convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, + (void **)dest, converted_size, True); } /** @@ -1564,14 +1569,8 @@ size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx, src_len &= ~1; } - dest_len = convert_string_talloc(ctx, - CH_UTF16LE, - CH_UNIX, - src, - src_len, - (void *)&dest, - True); - if (dest_len == (size_t)-1) { + if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, + (void *)&dest, &dest_len, True)) { dest_len = 0; } @@ -1614,83 +1613,103 @@ size_t pull_ucs2_fstring(char *dest, const void *src) * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src) +bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, + size_t *converted_size) { size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL - * - * @returns The number of bytes occupied by the string in the destination + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src) +bool pull_ucs2_allocate(char **dest, const smb_ucs2_t *src, + size_t *converted_size) { - size_t dest_len, src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t); + *dest = NULL; - if (!convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; + *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_utf8_allocate(char **dest, const char *src) +bool pull_utf8_allocate(char **dest, const char *src, size_t *converted_size) { - size_t dest_len, src_len = strlen(src)+1; + size_t src_len = strlen(src)+1; + *dest = NULL; - if (!convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, - (void **)dest, &dest_len, True)) - return (size_t)-1; - else - return dest_len; + return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL + * @parm converted_size set to the number of bytes occupied by the string in + * the destination on success. * - * @returns The number of bytes occupied by the string in the destination + * @return true if new buffer was correctly allocated, and string was + * converted. **/ -size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, + size_t *converted_size) { size_t src_len = strlen(src)+1; + *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True); + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, + (void **)dest, converted_size, True); } /** -- cgit From 03991ab0734ecbb87a75238d1356fbe0e5b1d38d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Aug 2008 13:35:15 -0700 Subject: Fix bug 5686 - libsmbclient segfaults with more than one SMBCCTX. Here is a patch to allow many subsystems to be re-initialized. The only functional change I made was to remove the null context tracking, as the memory allocated here is designed to be left for the complete lifetime of the program. Freeing this early (when all smb contexts are destroyed) could crash other users of talloc. Jeremy. (This used to be commit 8c630efd25cf17aff59448ca05c1b44a41964b16) --- source3/lib/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index b1a5393461..485212b100 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -47,6 +47,7 @@ char lp_failed_convert_char(void) static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; static bool conv_silent; /* Should we do a debug if the conversion fails ? */ +static bool initialized; /** * Return the name of a charset to give to iconv(). @@ -92,12 +93,10 @@ static const char *charset_name(charset_t ch) void lazy_initialize_conv(void) { - static int initialized = False; - if (!initialized) { - initialized = True; load_case_tables(); init_iconv(); + initialized = true; } } @@ -116,6 +115,7 @@ void gfree_charcnv(void) } } } + initialized = false; } /** -- cgit