From 6492d6b2f6a2743f5e794447911cbbba7e031d5d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 08:09:06 +0000 Subject: initial client side unicode support (needed for netapp filer) I've currently got this code disabled by default as it is incomplete. You enable it by setting a USE_UNICODE environment variable. Once the support is complete this check will be removed and the CAP_UNICODE capability bit will be the sole determination of whether the client library code uses unicode right now I have converted session_setup and tconx. I will do more fns over the next few days. see clistr.c for the new client side string interface. Luckily it tends to make the code smaller and neater while adding unicode support. (This used to be commit e1a04e621f1c28d8e6e543d43741ca0272e2237f) --- source3/libsmb/clistr.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 source3/libsmb/clistr.c (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c new file mode 100644 index 0000000000..839dec7592 --- /dev/null +++ b/source3/libsmb/clistr.c @@ -0,0 +1,161 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + client string routines + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define NO_SYSLOG + +#include "includes.h" + +/* we will delete this variable once our client side unicode support is complete */ +extern int cli_use_unicode; + +/**************************************************************************** +copy a string from a char* src to a unicode or ascii +dos code page destination choosing unicode or ascii based on the +cli->capabilities flag +return the number of bytes occupied by the string in the destination +flags can have: + CLISTR_TERMINATE means include the null termination + CLISTR_CONVERT means convert from unix to dos codepage + CLISTR_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 clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int flags) +{ + int len; + + /* treat a pstring as "unlimited" length */ + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + /* the server doesn't want unicode */ + safe_strcpy(dest, src, dest_len); + len = strlen(dest); + if (flags & CLISTR_TERMINATE) len++; + if (flags & CLISTR_CONVERT) unix_to_dos(dest,True); + if (flags & CLISTR_UPPER) strupper(dest); + return len; + } + + /* the server likes unicode. give it the works */ + if (flags & CLISTR_CONVERT) { + dos_PutUniCode(dest, src, dest_len, flags & CLISTR_TERMINATE); + } else { + ascii_to_unistr(dest, src, dest_len); + } + if (flags & CLISTR_UPPER) { + strupper_w(dest); + } + len = strlen(src)*2; + if (flags & CLISTR_TERMINATE) len += 2; + return len; +} + + +/**************************************************************************** +return the length that a string would occupy when copied with clistr_push() + CLISTR_TERMINATE means include the null termination + CLISTR_CONVERT means convert from unix to dos codepage + CLISTR_UPPER means uppercase in the destination +****************************************************************************/ +int clistr_push_size(struct cli_state *cli, char *src, int dest_len, int flags) +{ + int len = strlen(src); + if (flags & CLISTR_TERMINATE) len++; + if (cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; + return len; +} + +/**************************************************************************** +copy a string from a unicode or ascii source (depending on +cli->capabilities) to a char* destination +flags can have: + CLISTR_CONVERT means convert from dos to unix codepage + CLISTR_TERMINATE means the string in src is null terminated +if CLISTR_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 +****************************************************************************/ +int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int src_len, int flags) +{ + int len; + + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + /* the server doesn't want unicode */ + if (flags & CLISTR_TERMINATE) { + safe_strcpy(dest, src, dest_len); + len = strlen(src)+1; + } else { + if (src_len > dest_len) src_len = dest_len; + len = src_len; + memcpy(dest, src, len); + dest[len] = 0; + } + if (flags & CLISTR_CONVERT) dos_to_unix(dest,True); + return len; + } + + if (flags & CLISTR_TERMINATE) { + unistr_to_ascii(dest, src, dest_len); + len = strlen(dest)*2 + 2; + } else { + int i, c; + if (dest_len < src_len) src_len = dest_len; + for (i=0; i < src_len; i += 2) { + c = SVAL(src, i); + *dest++ = c; + } + *dest++ = 0; + len = src_len; + } + if (flags & CLISTR_CONVERT) dos_to_unix(dest,True); + return len; +} + +/**************************************************************************** +return the length that a string would occupy (not including the null) +when copied with clistr_pull() +if src_len is -1 then assume the source is null terminated +****************************************************************************/ +int clistr_pull_size(struct cli_state *cli, void *src, int src_len) +{ + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + return strlen(src); + } + return strlen_w(src); +} + +/**************************************************************************** +return an alignment of either 0 or 1 +if unicode is not negotiated then return 0 +otherwise return 1 if offset is off +****************************************************************************/ +int clistr_align(struct cli_state *cli, int offset) +{ + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) return 0; + return offset & 1; +} -- cgit From c565c98723f1fab04d47ae6076d742c8ee2dcb49 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 10:11:40 +0000 Subject: pipe opening now works with unicode (This used to be commit ba3ce3404e1cd2e9da3ba1708f6fc8a12c085ef2) --- source3/libsmb/clistr.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 839dec7592..eb66d08c30 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -47,6 +47,11 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int dest_len = sizeof(pstring); } + if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + dest++; + dest_len--; + } + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); @@ -77,12 +82,18 @@ return the length that a string would occupy when copied with clistr_push() CLISTR_TERMINATE means include the null termination CLISTR_CONVERT means convert from unix to dos codepage CLISTR_UPPER means uppercase in the destination +note that dest is only used for alignment purposes. No data is written. ****************************************************************************/ -int clistr_push_size(struct cli_state *cli, char *src, int dest_len, int flags) +int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, int flags) { int len = strlen(src); if (flags & CLISTR_TERMINATE) len++; if (cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; + + if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + len++; + } + return len; } @@ -104,6 +115,11 @@ int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int dest_len = sizeof(pstring); } + if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) { + src++; + if (src_len > 0) src_len--; + } + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ if (flags & CLISTR_TERMINATE) { @@ -143,6 +159,11 @@ if src_len is -1 then assume the source is null terminated ****************************************************************************/ int clistr_pull_size(struct cli_state *cli, void *src, int src_len) { + if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) { + src++; + if (src_len > 0) src_len--; + } + if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { return strlen(src); } -- cgit From c7c3db2f16e572e14c5d881b641271b2ab9aa4be Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 12:22:30 +0000 Subject: converted cli_list() (This used to be commit bdce09b77807c80281c1e169b7c4813c9238fbe3) --- source3/libsmb/clistr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index eb66d08c30..32168cae16 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -48,6 +48,7 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int } if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + *(char *)dest = 0; dest++; dest_len--; } @@ -90,7 +91,7 @@ int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, if (flags & CLISTR_TERMINATE) len++; if (cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; - if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + if (dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { len++; } -- cgit From f76015333a80521aa3f2a06524e4cebd5c4bda1a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Feb 2001 23:52:27 +0000 Subject: yipee! client unicode now works well with nt (This used to be commit 5b2ef8a1b914265c6072c968d2dad7d26c2aeffc) --- source3/libsmb/clistr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 32168cae16..4c7c8e3077 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -40,17 +40,18 @@ is -1 then no maxiumum is used ****************************************************************************/ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int flags) { - int len; + int len=0; /* treat a pstring as "unlimited" length */ if (dest_len == -1) { dest_len = sizeof(pstring); } - if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + if (clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { *(char *)dest = 0; dest++; dest_len--; + len++; } if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { @@ -72,7 +73,7 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int if (flags & CLISTR_UPPER) { strupper_w(dest); } - len = strlen(src)*2; + len += strlen(src)*2; if (flags & CLISTR_TERMINATE) len += 2; return len; } -- cgit From 3910d7baca440b21e66c1dc15556748c6f028085 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Feb 2001 02:51:22 +0000 Subject: added support for a CLISTR_ASCII flag so we can use a uniform interface for ascii-only fields (This used to be commit cdf0316610803e6743936b29f232b32f9ec81422) --- source3/libsmb/clistr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 4c7c8e3077..da40fba9e6 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -35,6 +35,7 @@ flags can have: CLISTR_TERMINATE means include the null termination CLISTR_CONVERT means convert from unix to dos codepage CLISTR_UPPER means uppercase in the destination + CLISTR_ASCII use ascii even with unicode servers dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used ****************************************************************************/ @@ -47,14 +48,14 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int dest_len = sizeof(pstring); } - if (clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { + if (!(flags & CLISTR_ASCII) && clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { *(char *)dest = 0; dest++; dest_len--; len++; } - if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + if ((flags & CLISTR_ASCII) || !cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -90,9 +91,9 @@ int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, { int len = strlen(src); if (flags & CLISTR_TERMINATE) len++; - if (cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; + if (!(flags & CLISTR_ASCII) && cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; - if (dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + if (!(flags & CLISTR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { len++; } -- cgit From a8ab9840786b8376283743de8eef861d382b3171 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Feb 2001 03:40:20 +0000 Subject: the unicode conversion of our client code is complete enough to be enabled by default you can disable it by setting the environment variable CLI_FORCE_ASCII (This used to be commit 4d59c08c5e6f54c0d6ced7650750cb987e77b6c9) --- source3/libsmb/clistr.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index da40fba9e6..9f46099ba9 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -23,9 +23,6 @@ #include "includes.h" -/* we will delete this variable once our client side unicode support is complete */ -extern int cli_use_unicode; - /**************************************************************************** copy a string from a char* src to a unicode or ascii dos code page destination choosing unicode or ascii based on the @@ -55,7 +52,7 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int len++; } - if ((flags & CLISTR_ASCII) || !cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + if ((flags & CLISTR_ASCII) || !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -91,7 +88,7 @@ int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, { int len = strlen(src); if (flags & CLISTR_TERMINATE) len++; - if (!(flags & CLISTR_ASCII) && cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2; + if (!(flags & CLISTR_ASCII) && (cli->capabilities & CAP_UNICODE)) len *= 2; if (!(flags & CLISTR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { len++; @@ -123,7 +120,7 @@ int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int if (src_len > 0) src_len--; } - if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + if (!(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ if (flags & CLISTR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -167,7 +164,7 @@ int clistr_pull_size(struct cli_state *cli, void *src, int src_len) if (src_len > 0) src_len--; } - if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) { + if (!(cli->capabilities & CAP_UNICODE)) { return strlen(src); } return strlen_w(src); @@ -180,6 +177,6 @@ otherwise return 1 if offset is off ****************************************************************************/ int clistr_align(struct cli_state *cli, int offset) { - if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) return 0; + if (!(cli->capabilities & CAP_UNICODE)) return 0; return offset & 1; } -- cgit From d689f00026541dd2cb87c6949fdc2f8eb3ad919f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Feb 2001 04:14:28 +0000 Subject: converted the last couple of functions in libsmb to be unicode the whole of libsmb should now do unicode where appropriate (This used to be commit ac7529d2b69826f8214d5632c31778cc87216653) --- source3/libsmb/clistr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 9f46099ba9..e07b4d5a63 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -36,7 +36,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 clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int flags) +int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags) { int len=0; @@ -84,7 +84,7 @@ return the length that a string would occupy when copied with clistr_push() CLISTR_UPPER means uppercase in the destination note that dest is only used for alignment purposes. No data is written. ****************************************************************************/ -int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, int flags) +int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags) { int len = strlen(src); if (flags & CLISTR_TERMINATE) len++; @@ -107,7 +107,7 @@ if CLISTR_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 ****************************************************************************/ -int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int src_len, int flags) +int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags) { int len; @@ -157,7 +157,7 @@ return the length that a string would occupy (not including the null) when copied with clistr_pull() if src_len is -1 then assume the source is null terminated ****************************************************************************/ -int clistr_pull_size(struct cli_state *cli, void *src, int src_len) +int clistr_pull_size(struct cli_state *cli, const void *src, int src_len) { if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) { src++; -- cgit From d33b294b9aa6059bd0831a264b427108bd2d5db2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 Feb 2001 05:11:06 +0000 Subject: fixed a bug in non-terminated unicode strings with clistr_pull() (This used to be commit 339bcfd05d3260a123ccf3c06429da6bfe621f74) --- source3/libsmb/clistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index e07b4d5a63..52137d9f78 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -140,7 +140,7 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len len = strlen(dest)*2 + 2; } else { int i, c; - if (dest_len < src_len) src_len = dest_len; + if (dest_len*2 < src_len) src_len = 2*dest_len; for (i=0; i < src_len; i += 2) { c = SVAL(src, i); *dest++ = c; -- cgit From 0d54de536c03f941739359a121a337aa33a2dc84 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 Feb 2001 06:53:42 +0000 Subject: made some LANMAN1 wildcard progress it now handles -M LANMAN1 -f '.x' -m '?x' nicely (This used to be commit e7ccb9be6da9b1426eb136b4a0a1171232471768) --- source3/libsmb/clistr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 52137d9f78..1835e15971 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -103,6 +103,7 @@ cli->capabilities) to a char* destination flags can have: CLISTR_CONVERT means convert from dos to unix codepage CLISTR_TERMINATE means the string in src is null terminated + CLISTR_UNICODE means to force as unicode if CLISTR_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 @@ -115,12 +116,12 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len dest_len = sizeof(pstring); } - if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) { + if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) { src++; if (src_len > 0) src_len--; } - if (!(cli->capabilities & CAP_UNICODE)) { + if (!(flags & CLISTR_UNICODE) && !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ if (flags & CLISTR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -159,7 +160,7 @@ if src_len is -1 then assume the source is null terminated ****************************************************************************/ int clistr_pull_size(struct cli_state *cli, const void *src, int src_len) { - if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) { + if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) { src++; if (src_len > 0) src_len--; } -- cgit From 45c2ee3ff2d01fdd0a2db9fa90457cff4663c43d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 10 Mar 2001 11:35:25 +0000 Subject: to use the same macros in the client and server rename the CLISTR_ macros to STR_ (This used to be commit 95c9e4e0ba8f37f565aaf136f41eb76489441ff7) --- source3/libsmb/clistr.c | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 1835e15971..c0e7231d7a 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -29,10 +29,10 @@ dos code page destination choosing unicode or ascii based on the cli->capabilities flag return the number of bytes occupied by the string in the destination flags can have: - CLISTR_TERMINATE means include the null termination - CLISTR_CONVERT means convert from unix to dos codepage - CLISTR_UPPER means uppercase in the destination - CLISTR_ASCII use ascii even with unicode servers + STR_TERMINATE means include the null termination + STR_CONVERT means convert from unix to dos codepage + STR_UPPER means uppercase in the destination + STR_ASCII use ascii even with unicode servers dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used ****************************************************************************/ @@ -45,52 +45,52 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len dest_len = sizeof(pstring); } - if (!(flags & CLISTR_ASCII) && clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { + if (!(flags & STR_ASCII) && clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { *(char *)dest = 0; dest++; dest_len--; len++; } - if ((flags & CLISTR_ASCII) || !(cli->capabilities & CAP_UNICODE)) { + if ((flags & STR_ASCII) || !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); - if (flags & CLISTR_TERMINATE) len++; - if (flags & CLISTR_CONVERT) unix_to_dos(dest,True); - if (flags & CLISTR_UPPER) strupper(dest); + if (flags & STR_TERMINATE) len++; + if (flags & STR_CONVERT) unix_to_dos(dest,True); + if (flags & STR_UPPER) strupper(dest); return len; } /* the server likes unicode. give it the works */ - if (flags & CLISTR_CONVERT) { - dos_PutUniCode(dest, src, dest_len, flags & CLISTR_TERMINATE); + if (flags & STR_CONVERT) { + dos_PutUniCode(dest, src, dest_len, flags & STR_TERMINATE); } else { ascii_to_unistr(dest, src, dest_len); } - if (flags & CLISTR_UPPER) { + if (flags & STR_UPPER) { strupper_w(dest); } len += strlen(src)*2; - if (flags & CLISTR_TERMINATE) len += 2; + if (flags & STR_TERMINATE) len += 2; return len; } /**************************************************************************** return the length that a string would occupy when copied with clistr_push() - CLISTR_TERMINATE means include the null termination - CLISTR_CONVERT means convert from unix to dos codepage - CLISTR_UPPER means uppercase in the destination + STR_TERMINATE means include the null termination + STR_CONVERT means convert from unix to dos codepage + STR_UPPER means uppercase in the destination note that dest is only used for alignment purposes. No data is written. ****************************************************************************/ int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags) { int len = strlen(src); - if (flags & CLISTR_TERMINATE) len++; - if (!(flags & CLISTR_ASCII) && (cli->capabilities & CAP_UNICODE)) len *= 2; + if (flags & STR_TERMINATE) len++; + if (!(flags & STR_ASCII) && (cli->capabilities & CAP_UNICODE)) len *= 2; - if (!(flags & CLISTR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { + if (!(flags & STR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { len++; } @@ -101,10 +101,10 @@ int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, i copy a string from a unicode or ascii source (depending on cli->capabilities) to a char* destination flags can have: - CLISTR_CONVERT means convert from dos to unix codepage - CLISTR_TERMINATE means the string in src is null terminated - CLISTR_UNICODE means to force as unicode -if CLISTR_TERMINATE is set then src_len is ignored + STR_CONVERT means convert from dos to unix codepage + STR_TERMINATE means the string in src is null terminated + STR_UNICODE means to force as unicode +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 ****************************************************************************/ @@ -121,9 +121,9 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len if (src_len > 0) src_len--; } - if (!(flags & CLISTR_UNICODE) && !(cli->capabilities & CAP_UNICODE)) { + if (!(flags & STR_UNICODE) && !(cli->capabilities & CAP_UNICODE)) { /* the server doesn't want unicode */ - if (flags & CLISTR_TERMINATE) { + if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); len = strlen(src)+1; } else { @@ -132,11 +132,11 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len memcpy(dest, src, len); dest[len] = 0; } - if (flags & CLISTR_CONVERT) dos_to_unix(dest,True); + if (flags & STR_CONVERT) dos_to_unix(dest,True); return len; } - if (flags & CLISTR_TERMINATE) { + if (flags & STR_TERMINATE) { unistr_to_ascii(dest, src, dest_len); len = strlen(dest)*2 + 2; } else { @@ -149,7 +149,7 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len *dest++ = 0; len = src_len; } - if (flags & CLISTR_CONVERT) dos_to_unix(dest,True); + if (flags & STR_CONVERT) dos_to_unix(dest,True); return len; } -- cgit From 9ea70bd00349bc391809bec374700c6d9ce2952b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Mar 2001 12:42:43 +0000 Subject: simpler clistr interface which handles individual packets having unicode bit set differently to capabilities (This used to be commit 34a0821e087810381996f5ff6cf3b4d7b9bb53a0) --- source3/libsmb/clistr.c | 52 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 45 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index c0e7231d7a..feed10fa4e 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -45,14 +45,14 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) { + if (!(flags & STR_ASCII) && clistr_align(cli->outbuf, dest)) { *(char *)dest = 0; dest++; dest_len--; len++; } - if ((flags & STR_ASCII) || !(cli->capabilities & CAP_UNICODE)) { + if ((flags & STR_ASCII) || !(SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -76,27 +76,6 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len return len; } - -/**************************************************************************** -return the length that a string would occupy when copied with clistr_push() - STR_TERMINATE means include the null termination - STR_CONVERT means convert from unix to dos codepage - STR_UPPER means uppercase in the destination -note that dest is only used for alignment purposes. No data is written. -****************************************************************************/ -int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags) -{ - int len = strlen(src); - if (flags & STR_TERMINATE) len++; - if (!(flags & STR_ASCII) && (cli->capabilities & CAP_UNICODE)) len *= 2; - - if (!(flags & STR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) { - len++; - } - - return len; -} - /**************************************************************************** copy a string from a unicode or ascii source (depending on cli->capabilities) to a char* destination @@ -116,12 +95,12 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len dest_len = sizeof(pstring); } - if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) { + if (clistr_align(cli->inbuf, src)) { src++; if (src_len > 0) src_len--; } - if (!(flags & STR_UNICODE) && !(cli->capabilities & CAP_UNICODE)) { + if (!(flags & STR_UNICODE) && !(SVAL(cli->inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -153,31 +132,14 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len return len; } -/**************************************************************************** -return the length that a string would occupy (not including the null) -when copied with clistr_pull() -if src_len is -1 then assume the source is null terminated -****************************************************************************/ -int clistr_pull_size(struct cli_state *cli, const void *src, int src_len) -{ - if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) { - src++; - if (src_len > 0) src_len--; - } - - if (!(cli->capabilities & CAP_UNICODE)) { - return strlen(src); - } - return strlen_w(src); -} /**************************************************************************** return an alignment of either 0 or 1 if unicode is not negotiated then return 0 otherwise return 1 if offset is off ****************************************************************************/ -int clistr_align(struct cli_state *cli, int offset) +int clistr_align(const void *buf, const void *p) { - if (!(cli->capabilities & CAP_UNICODE)) return 0; - return offset & 1; + if (!(SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) return 0; + return PTR_DIFF(p, buf) & 1; } -- cgit From 871a4294043e2e74d906f63ad97a31e35abd0374 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 Mar 2001 03:25:13 +0000 Subject: added STR_ASCII support to clistr_pull() (This used to be commit 797293811ef0a79eecc460c471135c89090f8c06) --- source3/libsmb/clistr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index feed10fa4e..93361053e0 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -95,12 +95,13 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len dest_len = sizeof(pstring); } - if (clistr_align(cli->inbuf, src)) { + if (!(flags & STR_ASCII) && clistr_align(cli->inbuf, src)) { src++; if (src_len > 0) src_len--; } - if (!(flags & STR_UNICODE) && !(SVAL(cli->inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) { + if ((flags & STR_ASCII) || + (!(flags & STR_UNICODE) && !(SVAL(cli->inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS))) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); -- cgit From cf313f6232e02577b0d79cc90e74cf8f20a81896 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 18 Mar 2001 22:47:17 +0000 Subject: fixed some compilation errors with IRIX cc (This used to be commit e430ded56e9c15a462a171e6350f1eddefa8dd11) --- source3/libsmb/clistr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 93361053e0..13bf1f05b7 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -47,7 +47,7 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len if (!(flags & STR_ASCII) && clistr_align(cli->outbuf, dest)) { *(char *)dest = 0; - dest++; + dest = (void *)((char *)dest + 1); dest_len--; len++; } @@ -96,7 +96,7 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len } if (!(flags & STR_ASCII) && clistr_align(cli->inbuf, src)) { - src++; + src = (void *)((char *)src + 1); if (src_len > 0) src_len--; } -- cgit From 350dc55c6e9d15dce5defb35b93d3a211865ae79 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 7 May 2001 01:48:03 +0000 Subject: Fixed a compiler warning. Still more const warnings though. )-: (This used to be commit a345b477a22f6261613d21d079b1632a9409c914) --- source3/libsmb/clistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 13bf1f05b7..0225797538 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -96,7 +96,7 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len } if (!(flags & STR_ASCII) && clistr_align(cli->inbuf, src)) { - src = (void *)((char *)src + 1); + src = (const void *)((const char *)src + 1); if (src_len > 0) src_len--; } -- cgit From fda0f83d751a1ea6c731fd6a82484a724a1c6e32 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Jun 2001 01:01:15 +0000 Subject: Following info from TAKAHASHI Motonobu , Samba Users Group Japan, ensure that we don't use dos_to_unix(xx,True), but always use dos_to_unix(xx,False) to prevent overwriting. Jeremy. (This used to be commit 244aec8ea623fec828add3ab09c5003bf32bd5c7) --- source3/libsmb/clistr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 0225797538..887b5e84c1 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -112,7 +112,8 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len memcpy(dest, src, len); dest[len] = 0; } - if (flags & STR_CONVERT) dos_to_unix(dest,True); + if (flags & STR_CONVERT) + safe_strcpy(dest,dos_to_unix(dest,False),dest_len); return len; } @@ -129,7 +130,8 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len *dest++ = 0; len = src_len; } - if (flags & STR_CONVERT) dos_to_unix(dest,True); + if (flags & STR_CONVERT) + safe_strcpy(dest,dos_to_unix(dest,False),dest_len); return len; } -- cgit From 4ff011d88ef5b79b92d2cea1abe32c93bc03f724 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jun 2001 05:38:28 +0000 Subject: Added STR_NOALIGN flags to clistr and srvstr fns. Yes, NT actually does send unaligned unicode strings sometimes! Fixed our handling of the workgroup name tacked on the end of the NT1 negprot response (a unaligned unicode) fixed a couple of places where we should be using the message_end fns instead of pre-calculated buffer lengths (This used to be commit 86613493a9b2e56523153486931d0bf8d39beb7a) --- source3/libsmb/clistr.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 887b5e84c1..762a24c22c 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -23,6 +23,10 @@ #include "includes.h" +#define UNICODE_FLAG(cli, flags) (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) + /**************************************************************************** copy a string from a char* src to a unicode or ascii dos code page destination choosing unicode or ascii based on the @@ -33,6 +37,7 @@ flags can have: STR_CONVERT means convert from unix to dos codepage STR_UPPER means uppercase in the destination STR_ASCII use ascii even with unicode servers + 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 ****************************************************************************/ @@ -45,14 +50,14 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && clistr_align(cli->outbuf, dest)) { + if (clistr_align(cli, dest, flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); dest_len--; len++; } - if ((flags & STR_ASCII) || !(SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) { + if (!UNICODE_FLAG(cli, flags)) { /* the server doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -83,6 +88,7 @@ flags can have: STR_CONVERT means convert from dos to unix codepage STR_TERMINATE means the string in src is null terminated STR_UNICODE means to force as unicode + 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 @@ -95,13 +101,12 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && clistr_align(cli->inbuf, src)) { + if (clistr_align(cli, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len > 0) src_len--; } - if ((flags & STR_ASCII) || - (!(flags & STR_UNICODE) && !(SVAL(cli->inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS))) { + if (!UNICODE_FLAG(cli, flags)) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -141,8 +146,8 @@ return an alignment of either 0 or 1 if unicode is not negotiated then return 0 otherwise return 1 if offset is off ****************************************************************************/ -int clistr_align(const void *buf, const void *p) +int clistr_align(struct cli_state *cli, const void *p, int flags) { - if (!(SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) return 0; - return PTR_DIFF(p, buf) & 1; + if ((flags & STR_NOALIGN) || !UNICODE_FLAG(cli, flags)) return 0; + return PTR_DIFF(p, cli->outbuf) & 1; } -- cgit From 82b76931cb62ea952fb0a4091880a8e0188530c8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Jul 2001 00:33:15 +0000 Subject: Insure caught the fact that PTRDIFFs were being done between two unrelated pointers. Jeremy. (This used to be commit 15c64199cb29e2fca6ee7353673dbb3f962e0e24) --- source3/libsmb/clistr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 762a24c22c..6dd3b751b4 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -50,7 +50,7 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len dest_len = sizeof(pstring); } - if (clistr_align(cli, dest, flags)) { + if (clistr_align_out(cli, dest, flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); dest_len--; @@ -101,7 +101,7 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len dest_len = sizeof(pstring); } - if (clistr_align(cli, src, flags)) { + if (clistr_align_in(cli, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len > 0) src_len--; } @@ -146,8 +146,20 @@ return an alignment of either 0 or 1 if unicode is not negotiated then return 0 otherwise return 1 if offset is off ****************************************************************************/ -int clistr_align(struct cli_state *cli, const void *p, int flags) +static int clistr_align(struct cli_state *cli, char *buf, const void *p, int flags) { if ((flags & STR_NOALIGN) || !UNICODE_FLAG(cli, flags)) return 0; - return PTR_DIFF(p, cli->outbuf) & 1; + return PTR_DIFF(p, buf) & 1; } + +int clistr_align_out(struct cli_state *cli, const void *p, int flags) +{ + return clistr_align(cli, cli->outbuf, p, flags); +} + +int clistr_align_in(struct cli_state *cli, const void *p, int flags) +{ + return clistr_align(cli, cli->inbuf, p, flags); +} + + -- 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/libsmb/clistr.c | 133 +++--------------------------------------------- 1 file changed, 6 insertions(+), 127 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 6dd3b751b4..baec3e5da8 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -19,147 +19,26 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" -#define UNICODE_FLAG(cli, flags) (!(flags & STR_ASCII) && \ - ((flags & STR_UNICODE || \ - (SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) - -/**************************************************************************** -copy a string from a char* src to a unicode or ascii -dos code page destination choosing unicode or ascii based on the -cli->capabilities flag -return the number of bytes occupied by the string in the destination -flags can have: - STR_TERMINATE means include the null termination - STR_CONVERT means convert from unix to dos codepage - STR_UPPER means uppercase in the destination - STR_ASCII use ascii even with unicode servers - 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 clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags) { - int len=0; - - /* treat a pstring as "unlimited" length */ - if (dest_len == -1) { - dest_len = sizeof(pstring); - } - - if (clistr_align_out(cli, dest, flags)) { - *(char *)dest = 0; - dest = (void *)((char *)dest + 1); - dest_len--; - len++; - } - - if (!UNICODE_FLAG(cli, flags)) { - /* the server doesn't want unicode */ - safe_strcpy(dest, src, dest_len); - len = strlen(dest); - if (flags & STR_TERMINATE) len++; - if (flags & STR_CONVERT) unix_to_dos(dest,True); - if (flags & STR_UPPER) strupper(dest); - return len; - } - - /* the server likes unicode. give it the works */ - if (flags & STR_CONVERT) { - dos_PutUniCode(dest, src, dest_len, flags & STR_TERMINATE); - } else { - ascii_to_unistr(dest, src, dest_len); - } - if (flags & STR_UPPER) { - strupper_w(dest); - } - len += strlen(src)*2; - if (flags & STR_TERMINATE) len += 2; - return len; + return push_string(cli->outbuf, dest, src, dest_len, flags); } -/**************************************************************************** -copy a string from a unicode or ascii source (depending on -cli->capabilities) to a char* destination -flags can have: - STR_CONVERT means convert from dos to unix codepage - STR_TERMINATE means the string in src is null terminated - STR_UNICODE means to force as unicode - 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 -****************************************************************************/ -int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags) +int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, + int flags) { - int len; - - if (dest_len == -1) { - dest_len = sizeof(pstring); - } - - if (clistr_align_in(cli, src, flags)) { - src = (const void *)((const char *)src + 1); - if (src_len > 0) src_len--; - } - - if (!UNICODE_FLAG(cli, flags)) { - /* the server doesn't want unicode */ - if (flags & STR_TERMINATE) { - safe_strcpy(dest, src, dest_len); - len = strlen(src)+1; - } else { - if (src_len > dest_len) src_len = dest_len; - len = src_len; - memcpy(dest, src, len); - dest[len] = 0; - } - if (flags & STR_CONVERT) - safe_strcpy(dest,dos_to_unix(dest,False),dest_len); - return len; - } - - if (flags & STR_TERMINATE) { - unistr_to_ascii(dest, src, dest_len); - len = strlen(dest)*2 + 2; - } else { - int i, c; - if (dest_len*2 < src_len) src_len = 2*dest_len; - for (i=0; i < src_len; i += 2) { - c = SVAL(src, i); - *dest++ = c; - } - *dest++ = 0; - len = src_len; - } - if (flags & STR_CONVERT) - safe_strcpy(dest,dos_to_unix(dest,False),dest_len); - return len; + return pull_string(cli->inbuf, dest, src, dest_len, src_len, flags); } -/**************************************************************************** -return an alignment of either 0 or 1 -if unicode is not negotiated then return 0 -otherwise return 1 if offset is off -****************************************************************************/ -static int clistr_align(struct cli_state *cli, char *buf, const void *p, int flags) -{ - if ((flags & STR_NOALIGN) || !UNICODE_FLAG(cli, flags)) return 0; - return PTR_DIFF(p, buf) & 1; -} - int clistr_align_out(struct cli_state *cli, const void *p, int flags) { - return clistr_align(cli, cli->outbuf, p, flags); + return align_string(cli->outbuf, p, flags); } int clistr_align_in(struct cli_state *cli, const void *p, int flags) { - return clistr_align(cli, cli->inbuf, p, flags); + return align_string(cli->inbuf, p, flags); } - - -- 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/libsmb/clistr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index baec3e5da8..3c9964368e 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. client string routines Copyright (C) Andrew Tridgell 2001 -- 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/libsmb/clistr.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 3c9964368e..97a3fa6cc9 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -20,24 +20,38 @@ #include "includes.h" -int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags) +size_t clistr_push_fn(const char *function, unsigned int line, + struct cli_state *cli, void *dest, + const char *src, int dest_len, int flags) { - return push_string(cli->outbuf, dest, src, dest_len, flags); + size_t buf_used = PTR_DIFF(dest, cli->outbuf); + if (dest_len == -1) { + if (((ptrdiff_t)dest < (ptrdiff_t)cli->outbuf) || (buf_used > cli->bufsize)) { + DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); + return push_string_fn(function, line, cli->outbuf, dest, src, -1, flags); + } + return push_string_fn(function, line, cli->outbuf, dest, src, cli->bufsize - buf_used, flags); + } + + /* 'normal' push into size-specified buffer */ + return push_string_fn(function, line, cli->outbuf, dest, src, dest_len, flags); } -int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, - int flags) +size_t clistr_pull_fn(const char *function, unsigned int line, + struct cli_state *cli, char *dest, const void *src, + int dest_len, int src_len, + int flags) { - return pull_string(cli->inbuf, dest, src, dest_len, src_len, flags); + return pull_string_fn(function, line, cli->inbuf, dest, src, dest_len, src_len, flags); } -int clistr_align_out(struct cli_state *cli, const void *p, int flags) +size_t clistr_align_out(struct cli_state *cli, const void *p, int flags) { return align_string(cli->outbuf, p, flags); } -int clistr_align_in(struct cli_state *cli, const void *p, int flags) +size_t clistr_align_in(struct cli_state *cli, const void *p, int flags) { return align_string(cli->inbuf, p, flags); } -- cgit From 1f499a79f5468e87d26b60ffe3aa375b91cadbef Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Mar 2003 13:47:42 +0000 Subject: (merge from HEAD) Small clenaup patches: - safe_string.h - don't assume that __FUNCTION__ is available - process.c - use new workaround from safe_string.h for the same - util.c - Show how many bytes we smb_panic()ed trying to smb_xmalloc() - gencache.c - Keep valgrind quiet by always null terminating. - clistr.c - Add copyright - srvstr.h - move srvstr_push into a .c file again, as a real function. - srvstr.c - revive, with 'safe' checked srvstr_push - loadparm.c - set a default for the display charset. - connection.c - use safe_strcpy() Andrew Bartlett (This used to be commit c91e76bddbe1244ddc8d12b092eba875834029ac) --- source3/libsmb/clistr.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 97a3fa6cc9..bba9fcf15a 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. client string routines Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 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 -- cgit From e0cf81f1044eab1156dc30c06e7e788b640499f9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 02:27:41 +0000 Subject: Whitespace syncup. (This used to be commit 93101a93dabe2dd7a6420e90acf82e0e08dce572) --- source3/libsmb/clistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index bba9fcf15a..c61445c073 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -3,7 +3,7 @@ client string routines Copyright (C) Andrew Tridgell 2001 Copyright (C) Andrew Bartlett 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 2 of the License, or -- cgit From 02eea79624c85fb5ce6c3ffefe2d27e40c5ff97f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 31 Jul 2006 03:53:39 +0000 Subject: r17333: Some C++ warnings (This used to be commit be9aaffdaccae06c8c035eaf31862e34b7cfbe38) --- source3/libsmb/clistr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index c61445c073..6191f99ea9 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -49,10 +49,10 @@ size_t clistr_pull_fn(const char *function, unsigned int line, size_t clistr_align_out(struct cli_state *cli, const void *p, int flags) { - return align_string(cli->outbuf, p, flags); + return align_string(cli->outbuf, (const char *)p, flags); } size_t clistr_align_in(struct cli_state *cli, const void *p, int flags) { - return align_string(cli->inbuf, p, flags); + return align_string(cli->inbuf, (const char *)p, flags); } -- 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/libsmb/clistr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 6191f99ea9..4d18434ff9 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -43,7 +43,9 @@ size_t clistr_pull_fn(const char *function, unsigned int line, int dest_len, int src_len, int flags) { - return pull_string_fn(function, line, cli->inbuf, dest, src, dest_len, src_len, flags); + return pull_string_fn(function, line, cli->inbuf, + SVAL(cli->inbuf, smb_flg2), 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/libsmb/clistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 4d18434ff9..d3aab42dc6 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/libsmb/clistr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index d3aab42dc6..7e6ad790fc 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 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/libsmb/clistr.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 7e6ad790fc..39315729c4 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -28,13 +28,21 @@ size_t clistr_push_fn(const char *function, unsigned int line, if (dest_len == -1) { if (((ptrdiff_t)dest < (ptrdiff_t)cli->outbuf) || (buf_used > cli->bufsize)) { DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); - return push_string_fn(function, line, cli->outbuf, dest, src, -1, flags); + return push_string_fn(function, line, + cli->outbuf, + SVAL(cli->outbuf, smb_flg2), + dest, src, -1, flags); } - return push_string_fn(function, line, cli->outbuf, dest, src, cli->bufsize - buf_used, flags); + return push_string_fn(function, line, cli->outbuf, + SVAL(cli->outbuf, smb_flg2), + dest, src, cli->bufsize - buf_used, + flags); } /* 'normal' push into size-specified buffer */ - return push_string_fn(function, line, cli->outbuf, dest, src, dest_len, flags); + return push_string_fn(function, line, cli->outbuf, + SVAL(cli->outbuf, smb_flg2), + dest, src, dest_len, flags); } size_t clistr_pull_fn(const char *function, unsigned int line, -- 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/libsmb/clistr.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'source3/libsmb/clistr.c') diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c index 39315729c4..5d20d632aa 100644 --- a/source3/libsmb/clistr.c +++ b/source3/libsmb/clistr.c @@ -20,9 +20,13 @@ #include "includes.h" -size_t clistr_push_fn(const char *function, unsigned int line, - struct cli_state *cli, void *dest, - const char *src, int dest_len, int flags) +size_t clistr_push_fn(const char *function, + unsigned int line, + struct cli_state *cli, + void *dest, + const char *src, + int dest_len, + int flags) { size_t buf_used = PTR_DIFF(dest, cli->outbuf); if (dest_len == -1) { @@ -38,23 +42,46 @@ size_t clistr_push_fn(const char *function, unsigned int line, dest, src, cli->bufsize - buf_used, flags); } - + /* 'normal' push into size-specified buffer */ return push_string_fn(function, line, cli->outbuf, SVAL(cli->outbuf, smb_flg2), dest, src, dest_len, flags); } -size_t clistr_pull_fn(const char *function, unsigned int line, - struct cli_state *cli, char *dest, const void *src, - int dest_len, int src_len, - int flags) +size_t clistr_pull_fn(const char *function, + unsigned int line, + struct cli_state *cli, + char *dest, + const void *src, + int dest_len, + int src_len, + int flags) { return pull_string_fn(function, line, cli->inbuf, SVAL(cli->inbuf, smb_flg2), dest, src, dest_len, src_len, flags); } +size_t clistr_pull_talloc_fn(const char *function, + unsigned int line, + TALLOC_CTX *ctx, + struct cli_state *cli, + char **pp_dest, + const void *src, + int src_len, + int flags) +{ + return pull_string_talloc_fn(function, + line, + ctx, + cli->inbuf, + SVAL(cli->inbuf, smb_flg2), + pp_dest, + src, + src_len, + flags); +} size_t clistr_align_out(struct cli_state *cli, const void *p, int flags) { -- cgit