From b08b70faf873455ff14dcd633a7c9eb860ba4b28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 10 Mar 2001 11:38:27 +0000 Subject: started support for unicode on the wire in smbd. Using a very similar method to what was used in the client I now have session setup and tconx working. Currently this is enabled with SMBD_USE_UNICODE environment variable. Once the code is complete this will become a smb.conf option. (This used to be commit 7684c1e67294266d018c6f0cab58f1a9d797174f) --- source3/smbd/srvstr.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 source3/smbd/srvstr.c (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c new file mode 100644 index 0000000000..e420b8fa99 --- /dev/null +++ b/source3/smbd/srvstr.c @@ -0,0 +1,186 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + server specific 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" + +#define UNICODE_FLAG() (SVAL(inbuf, 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 +FLAGS2_UNICODE_STRINGS bit in inbuf +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 +dest_len is the maximum length allowed in the destination. If dest_len +is -1 then no maxiumum is used +****************************************************************************/ +int srvstr_push(void *inbuf, void *outbuf, 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 (!(flags & STR_ASCII) && srvstr_align(inbuf, PTR_DIFF(dest, outbuf))) { + *(char *)dest = 0; + dest++; + dest_len--; + len++; + } + + if ((flags & STR_ASCII) || !UNICODE_FLAG()) { + /* the client 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 the length that a string would occupy when copied with srvstr_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 srvstr_push_size(void *inbuf, void *outbuf, + const void *dest, const char *src, int dest_len, int flags) +{ + int len = strlen(src); + if (flags & STR_TERMINATE) len++; + if (!(flags & STR_ASCII) && UNICODE_FLAG()) len *= 2; + + if (!(flags & STR_ASCII) && dest && srvstr_align(inbuf, PTR_DIFF(outbuf, dest))) { + len++; + } + + return len; +} + +/**************************************************************************** +copy a string from a unicode or ascii source (depending on flg2) +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 +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 srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_len, int flags) +{ + int len; + + if (dest_len == -1) { + dest_len = sizeof(pstring); + } + + if (srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { + src++; + if (src_len > 0) src_len--; + } + + if (!(flags & STR_UNICODE) && !UNICODE_FLAG()) { + /* 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) dos_to_unix(dest,True); + 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) dos_to_unix(dest,True); + return len; +} + +/**************************************************************************** +return the length that a string would occupy (not including the null) +when copied with srvstr_pull() +if src_len is -1 then assume the source is null terminated +****************************************************************************/ +int srvstr_pull_size(void *inbuf, const void *src, int src_len) +{ + if (srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { + src++; + if (src_len > 0) src_len--; + } + + if (!UNICODE_FLAG()) { + 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 srvstr_align(void *inbuf, int offset) +{ + if (!UNICODE_FLAG()) return 0; + return offset & 1; +} -- cgit From 26f63881e242947e7d4a5f5c3ce6f13305d2601e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Mar 2001 03:45:29 +0000 Subject: added STR_ASCII flag to srvstr_pull() (This used to be commit e54d37903013df1c799ab3aaa10f10df24e3de61) --- source3/smbd/srvstr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index e420b8fa99..b944ed2578 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -119,12 +119,12 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ dest_len = sizeof(pstring); } - if (srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { + if (!(flags & STR_ASCII) && srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { src++; if (src_len > 0) src_len--; } - if (!(flags & STR_UNICODE) && !UNICODE_FLAG()) { + if ((flags & STR_ASCII) || (!(flags & STR_UNICODE) && !UNICODE_FLAG())) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); -- cgit From ff0462cde830a306105b9d585a36239f27e38f23 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 13 Mar 2001 22:00:46 +0000 Subject: simpler and more correct srvstr_push() it now uses outbuf not inbuf for the unicode flag, which allows for some server fns to be ascii and means one less parameter in push calls (This used to be commit a6dd6662267eeddf368ff0ffba76b45761bf4eeb) --- source3/smbd/srvstr.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index b944ed2578..c3eef46440 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -23,7 +23,7 @@ #include "includes.h" -#define UNICODE_FLAG() (SVAL(inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS) +#define UNICODE_FLAG(buf) (SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS) /**************************************************************************** copy a string from a char* src to a unicode or ascii @@ -38,7 +38,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 srvstr_push(void *inbuf, void *outbuf, void *dest, const char *src, int dest_len, int flags) +int srvstr_push(void *outbuf, void *dest, const char *src, int dest_len, int flags) { int len=0; @@ -47,14 +47,14 @@ int srvstr_push(void *inbuf, void *outbuf, void *dest, const char *src, int dest dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && srvstr_align(inbuf, PTR_DIFF(dest, outbuf))) { + if (!(flags & STR_ASCII) && srvstr_align(outbuf, PTR_DIFF(dest, outbuf))) { *(char *)dest = 0; dest++; dest_len--; len++; } - if ((flags & STR_ASCII) || !UNICODE_FLAG()) { + if ((flags & STR_ASCII) || !UNICODE_FLAG(outbuf)) { /* the client doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -86,14 +86,14 @@ return the length that a string would occupy when copied with srvstr_push() STR_UPPER means uppercase in the destination note that dest is only used for alignment purposes. No data is written. ****************************************************************************/ -int srvstr_push_size(void *inbuf, void *outbuf, +int srvstr_push_size(void *outbuf, const void *dest, const char *src, int dest_len, int flags) { int len = strlen(src); if (flags & STR_TERMINATE) len++; - if (!(flags & STR_ASCII) && UNICODE_FLAG()) len *= 2; + if (!(flags & STR_ASCII) && UNICODE_FLAG(outbuf)) len *= 2; - if (!(flags & STR_ASCII) && dest && srvstr_align(inbuf, PTR_DIFF(outbuf, dest))) { + if (!(flags & STR_ASCII) && dest && srvstr_align(outbuf, PTR_DIFF(outbuf, dest))) { len++; } @@ -124,7 +124,7 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ if (src_len > 0) src_len--; } - if ((flags & STR_ASCII) || (!(flags & STR_UNICODE) && !UNICODE_FLAG())) { + if ((flags & STR_ASCII) || (!(flags & STR_UNICODE) && !UNICODE_FLAG(inbuf))) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -168,7 +168,7 @@ int srvstr_pull_size(void *inbuf, const void *src, int src_len) if (src_len > 0) src_len--; } - if (!UNICODE_FLAG()) { + if (!UNICODE_FLAG(inbuf)) { return strlen(src); } return strlen_w(src); @@ -181,6 +181,6 @@ otherwise return 1 if offset is off ****************************************************************************/ int srvstr_align(void *inbuf, int offset) { - if (!UNICODE_FLAG()) return 0; + if (!UNICODE_FLAG(inbuf)) return 0; return offset & 1; } -- cgit From fbab616c149a9549f30c7f9f0550386c815b69e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Mar 2001 12:45:46 +0000 Subject: don't need srvstr_push_size or srvstr_pull_size (This used to be commit d5b39a1d435f7fe79eb556f7e6b55276ac68a73d) --- source3/smbd/srvstr.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index c3eef46440..241a74f02f 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -78,28 +78,6 @@ int srvstr_push(void *outbuf, void *dest, const char *src, int dest_len, int fla return len; } - -/**************************************************************************** -return the length that a string would occupy when copied with srvstr_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 srvstr_push_size(void *outbuf, - const void *dest, const char *src, int dest_len, int flags) -{ - int len = strlen(src); - if (flags & STR_TERMINATE) len++; - if (!(flags & STR_ASCII) && UNICODE_FLAG(outbuf)) len *= 2; - - if (!(flags & STR_ASCII) && dest && srvstr_align(outbuf, PTR_DIFF(outbuf, dest))) { - len++; - } - - return len; -} - /**************************************************************************** copy a string from a unicode or ascii source (depending on flg2) to a char* destination @@ -156,24 +134,6 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ return len; } -/**************************************************************************** -return the length that a string would occupy (not including the null) -when copied with srvstr_pull() -if src_len is -1 then assume the source is null terminated -****************************************************************************/ -int srvstr_pull_size(void *inbuf, const void *src, int src_len) -{ - if (srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { - src++; - if (src_len > 0) src_len--; - } - - if (!UNICODE_FLAG(inbuf)) { - return strlen(src); - } - return strlen_w(src); -} - /**************************************************************************** return an alignment of either 0 or 1 if unicode is not negotiated then return 0 -- 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/smbd/srvstr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 241a74f02f..55cbada10c 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -49,7 +49,7 @@ int srvstr_push(void *outbuf, void *dest, const char *src, int dest_len, int fla if (!(flags & STR_ASCII) && srvstr_align(outbuf, PTR_DIFF(dest, outbuf))) { *(char *)dest = 0; - dest++; + dest = (void *)((char *)dest + 1); dest_len--; len++; } @@ -98,7 +98,7 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ } if (!(flags & STR_ASCII) && srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { - src++; + src = (void *)((char *)src + 1); if (src_len > 0) src_len--; } -- cgit From 578a9fabfb08740bd13af7418ceda41d1341cc5d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 31 Mar 2001 13:48:24 +0000 Subject: started converting some of the only-ascii code to use srvstr_* added srvstr_push_ascii() and srvstr_pull_ascii() as convenience routines to replace the current usage of strncpy() like fns for packet pull/push. We need to do this in *lots* of places in Samba in order to get our codepage handling right (This used to be commit 8b0e3679a6dc479c0e3177707dff386559779b69) --- source3/smbd/srvstr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 55cbada10c..6ca34a2428 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -144,3 +144,21 @@ int srvstr_align(void *inbuf, int offset) if (!UNICODE_FLAG(inbuf)) return 0; return offset & 1; } + + +/**************************************************************************** +these are useful for replacing all those StrnCpy() ops for copying data +to/from the wire +****************************************************************************/ + +int srvstr_push_ascii(void *dest, const char *src, int dest_len) +{ + return srvstr_push(NULL, dest, src, dest_len, + STR_ASCII|STR_CONVERT|STR_TERMINATE); +} + +int srvstr_pull_ascii(char *dest, const void *src, int dest_len) +{ + return srvstr_pull(NULL, dest, src, dest_len, -1, + STR_ASCII|STR_CONVERT|STR_TERMINATE); +} -- 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/smbd/srvstr.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 6ca34a2428..0651fb725b 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -23,7 +23,20 @@ #include "includes.h" -#define UNICODE_FLAG(buf) (SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS) +#define UNICODE_FLAG(buf, flags) (!(flags & STR_ASCII) && \ + ((flags & STR_UNICODE || \ + (SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) + +/**************************************************************************** +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 srvstr_align(void *inbuf, int offset, int flags) +{ + if ((flags & STR_NOALIGN) || !UNICODE_FLAG(inbuf, flags)) return 0; + return offset & 1; +} /**************************************************************************** copy a string from a char* src to a unicode or ascii @@ -35,6 +48,8 @@ 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_UNICODE means to force as unicode + 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 ****************************************************************************/ @@ -47,14 +62,14 @@ int srvstr_push(void *outbuf, void *dest, const char *src, int dest_len, int fla dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && srvstr_align(outbuf, PTR_DIFF(dest, outbuf))) { + if (srvstr_align(outbuf, PTR_DIFF(dest, outbuf), flags)) { *(char *)dest = 0; dest = (void *)((char *)dest + 1); dest_len--; len++; } - if ((flags & STR_ASCII) || !UNICODE_FLAG(outbuf)) { + if (!UNICODE_FLAG(outbuf, flags)) { /* the client doesn't want unicode */ safe_strcpy(dest, src, dest_len); len = strlen(dest); @@ -85,6 +100,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 @@ -97,12 +113,12 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ dest_len = sizeof(pstring); } - if (!(flags & STR_ASCII) && srvstr_align(inbuf, PTR_DIFF(src, inbuf))) { + if (srvstr_align(inbuf, PTR_DIFF(src, inbuf), flags)) { src = (void *)((char *)src + 1); if (src_len > 0) src_len--; } - if ((flags & STR_ASCII) || (!(flags & STR_UNICODE) && !UNICODE_FLAG(inbuf))) { + if (!UNICODE_FLAG(inbuf, flags)) { /* the server doesn't want unicode */ if (flags & STR_TERMINATE) { safe_strcpy(dest, src, dest_len); @@ -134,18 +150,6 @@ int srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_ return len; } -/**************************************************************************** -return an alignment of either 0 or 1 -if unicode is not negotiated then return 0 -otherwise return 1 if offset is off -****************************************************************************/ -int srvstr_align(void *inbuf, int offset) -{ - if (!UNICODE_FLAG(inbuf)) return 0; - return offset & 1; -} - - /**************************************************************************** these are useful for replacing all those StrnCpy() ops for copying data to/from the wire -- 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/smbd/srvstr.c | 145 ++------------------------------------------------ 1 file changed, 5 insertions(+), 140 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 0651fb725b..3c452653f2 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -19,150 +19,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define NO_SYSLOG - #include "includes.h" -#define UNICODE_FLAG(buf, flags) (!(flags & STR_ASCII) && \ - ((flags & STR_UNICODE || \ - (SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) - -/**************************************************************************** -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 srvstr_align(void *inbuf, int offset, int flags) -{ - if ((flags & STR_NOALIGN) || !UNICODE_FLAG(inbuf, flags)) return 0; - return offset & 1; -} - -/**************************************************************************** -copy a string from a char* src to a unicode or ascii -dos code page destination choosing unicode or ascii based on the -FLAGS2_UNICODE_STRINGS bit in inbuf -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_UNICODE means to force as unicode - 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 srvstr_push(void *outbuf, 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 (srvstr_align(outbuf, PTR_DIFF(dest, outbuf), flags)) { - *(char *)dest = 0; - dest = (void *)((char *)dest + 1); - dest_len--; - len++; - } - - if (!UNICODE_FLAG(outbuf, flags)) { - /* the client 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; -} - -/**************************************************************************** -copy a string from a unicode or ascii source (depending on flg2) -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 srvstr_pull(void *inbuf, char *dest, const void *src, int dest_len, int src_len, int flags) -{ - int len; - - if (dest_len == -1) { - dest_len = sizeof(pstring); - } - - if (srvstr_align(inbuf, PTR_DIFF(src, inbuf), flags)) { - src = (void *)((char *)src + 1); - if (src_len > 0) src_len--; - } - - if (!UNICODE_FLAG(inbuf, 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) dos_to_unix(dest,True); - 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) dos_to_unix(dest,True); - return len; -} - -/**************************************************************************** -these are useful for replacing all those StrnCpy() ops for copying data -to/from the wire -****************************************************************************/ - -int srvstr_push_ascii(void *dest, const char *src, int dest_len) +int srvstr_push(void *base_ptr, void *dest, const char *src, int dest_len, int flags) { - return srvstr_push(NULL, dest, src, dest_len, - STR_ASCII|STR_CONVERT|STR_TERMINATE); + return push_string(base_ptr, dest, src, dest_len, flags); } -int srvstr_pull_ascii(char *dest, const void *src, int dest_len) +int srvstr_pull(void *base_ptr, char *dest, const void *src, int dest_len, int src_len, + int flags) { - return srvstr_pull(NULL, dest, src, dest_len, -1, - STR_ASCII|STR_CONVERT|STR_TERMINATE); + return pull_string(base_ptr, dest, src, dest_len, src_len, 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/smbd/srvstr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 3c452653f2..90da422f13 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. server specific string routines Copyright (C) Andrew Tridgell 2001 -- 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/smbd/srvstr.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 90da422f13..36fecf5bd2 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -30,3 +30,12 @@ int srvstr_pull(void *base_ptr, char *dest, const void *src, int dest_len, int s { return pull_string(base_ptr, dest, src, dest_len, src_len, flags); } + +/* pull a string from the smb_buf part of a packet. In this case the + string can either be null terminated or it can be terminated by the + end of the smbbuf area +*/ +int srvstr_pull_buf(void *inbuf, char *dest, const void *src, int dest_len, int flags) +{ + return pull_string(inbuf, dest, src, dest_len, smb_bufrem(inbuf, src), flags); +} -- cgit From d5ee9b2f480ddbda0b8f69409698d27c99384f9c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Mar 2003 11:22:52 +0000 Subject: Jeremy merged across my string parinoia fixes, but forgot to enable them! :-) This patch catches up on the rest of the work - as much string checking as is possible is done at compile time, and the rest at runtime. Lots of code converted to pstrcpy() etc, and other code reworked to correctly call sizeof(). Andrew Bartlett (This used to be commit c5b604e2ee67d74241ae2fa07ae904647d35a2be) --- source3/smbd/srvstr.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 source3/smbd/srvstr.c (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c deleted file mode 100644 index 36fecf5bd2..0000000000 --- a/source3/smbd/srvstr.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - Unix SMB/CIFS implementation. - server specific 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. -*/ - -#include "includes.h" - -int srvstr_push(void *base_ptr, void *dest, const char *src, int dest_len, int flags) -{ - return push_string(base_ptr, dest, src, dest_len, flags); -} - -int srvstr_pull(void *base_ptr, char *dest, const void *src, int dest_len, int src_len, - int flags) -{ - return pull_string(base_ptr, dest, src, dest_len, src_len, flags); -} - -/* pull a string from the smb_buf part of a packet. In this case the - string can either be null terminated or it can be terminated by the - end of the smbbuf area -*/ -int srvstr_pull_buf(void *inbuf, char *dest, const void *src, int dest_len, int flags) -{ - return pull_string(inbuf, dest, src, dest_len, smb_bufrem(inbuf, src), 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/smbd/srvstr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 source3/smbd/srvstr.c (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c new file mode 100644 index 0000000000..409fd30a67 --- /dev/null +++ b/source3/smbd/srvstr.c @@ -0,0 +1,44 @@ +/* + Unix SMB/CIFS implementation. + server specific 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 + (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 max_send; + +/* Make sure we can't write a string past the end of the buffer */ + +size_t srvstr_push_fn(const char *function, unsigned int line, + const char *base_ptr, void *dest, + const char *src, int dest_len, int flags) +{ + size_t buf_used = PTR_DIFF(dest, base_ptr); + if (dest_len == -1) { + if (((ptrdiff_t)dest < (ptrdiff_t)base_ptr) || (buf_used > (size_t)max_send)) { +#if 0 + DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); +#endif + return push_string_fn(function, line, base_ptr, dest, src, -1, flags); + } + return push_string_fn(function, line, base_ptr, dest, src, max_send - buf_used, flags); + } + + /* 'normal' push into size-specified buffer */ + return push_string_fn(function, line, base_ptr, dest, src, dest_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/smbd/srvstr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 409fd30a67..21474c5c3c 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.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/smbd/srvstr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 21474c5c3c..4462a423c8 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.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 944fe69d03f1fcd6ab680fcb672d06036f89f251 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jul 2007 10:52:39 +0000 Subject: r24000: Add message_push_blob() and message_push_string(). The proposed new API convention is to start with a 0 bcc length and then push things step by step. These routines reallocate the outbuf and adjust the length and bcc fields as necessary. (This used to be commit 624f1fe4f6e022d73e78fa8c9646f6f64035f3ee) --- source3/smbd/srvstr.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 4462a423c8..1daa25553f 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -41,3 +41,43 @@ size_t srvstr_push_fn(const char *function, unsigned int line, /* 'normal' push into size-specified buffer */ return push_string_fn(function, line, base_ptr, dest, src, dest_len, flags); } + +/******************************************************************* + Add a string to the end of a smb_buf, adjusting bcc and smb_len. + Return the bytes added +********************************************************************/ + +ssize_t message_push_string(uint8 **outbuf, const char *str, int flags) +{ + size_t buf_size = smb_len(*outbuf) + 4; + size_t grow_size; + size_t result; + uint8 *tmp; + + /* + * We need to over-allocate, now knowing what srvstr_push will + * actually use. This is very generous by incorporating potential + * padding, the terminating 0 and at most 4 chars per UTF-16 code + * point. + */ + grow_size = (strlen(str) + 2) * 4; + + if (!(tmp = TALLOC_REALLOC_ARRAY(NULL, *outbuf, uint8, + buf_size + grow_size))) { + DEBUG(0, ("talloc failed\n")); + return -1; + } + + result = srvstr_push((char *)tmp, tmp + buf_size, str, grow_size, + flags); + + if (result == (size_t)-1) { + DEBUG(0, ("srvstr_push failed\n")); + return -1; + } + set_message_bcc(NULL, (char *)tmp, smb_buflen(tmp) + result); + + *outbuf = tmp; + + return result; +} -- cgit From 6c6fed5e656d64df9c9c12d7909f2c2289208bf7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 2 Aug 2007 17:37:38 +0000 Subject: r24130: Explicitly pass flags2 to srvstr_push This is in preparation of the trans2 conversion: srvstr_push should not look at inbuf directly. (This used to be commit 5fd7e6a3821bea26d352e3edc23b7a216b1200e5) --- source3/smbd/srvstr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 1daa25553f..df993537ba 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -24,7 +24,7 @@ extern int max_send; /* Make sure we can't write a string past the end of the buffer */ size_t srvstr_push_fn(const char *function, unsigned int line, - const char *base_ptr, void *dest, + const char *base_ptr, uint16 smb_flags2, void *dest, const char *src, int dest_len, int flags) { size_t buf_used = PTR_DIFF(dest, base_ptr); @@ -68,8 +68,8 @@ ssize_t message_push_string(uint8 **outbuf, const char *str, int flags) return -1; } - result = srvstr_push((char *)tmp, tmp + buf_size, str, grow_size, - flags); + result = srvstr_push((char *)tmp, SVAL(tmp, smb_flg2), + tmp + buf_size, str, grow_size, flags); if (result == (size_t)-1) { DEBUG(0, ("srvstr_push failed\n")); -- 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/smbd/srvstr.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index df993537ba..fbcf249ffb 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -33,13 +33,17 @@ size_t srvstr_push_fn(const char *function, unsigned int line, #if 0 DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); #endif - return push_string_fn(function, line, base_ptr, dest, src, -1, flags); + return push_string_fn(function, line, base_ptr, + smb_flags2, dest, src, -1, + flags); } - return push_string_fn(function, line, base_ptr, dest, src, max_send - buf_used, flags); + return push_string_fn(function, line, base_ptr, smb_flags2, + dest, src, max_send - buf_used, flags); } /* 'normal' push into size-specified buffer */ - return push_string_fn(function, line, base_ptr, dest, src, dest_len, flags); + return push_string_fn(function, line, base_ptr, smb_flags2, dest, src, + dest_len, flags); } /******************************************************************* -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/smbd/srvstr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index fbcf249ffb..68e61033ae 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -79,7 +79,7 @@ ssize_t message_push_string(uint8 **outbuf, const char *str, int flags) DEBUG(0, ("srvstr_push failed\n")); return -1; } - set_message_bcc(NULL, (char *)tmp, smb_buflen(tmp) + result); + set_message_bcc((char *)tmp, smb_buflen(tmp) + result); *outbuf = tmp; -- cgit From 6ff701e695e847414afb0320a6701fe252d3f311 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Nov 2007 13:14:24 -0800 Subject: Match the 3.0.27a version of this function. Jeremy. (This used to be commit 629406cbe77a5d56a258ac414ab47f3e89183e52) --- source3/smbd/srvstr.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'source3/smbd/srvstr.c') diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index 68e61033ae..bae77d5d4b 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -23,24 +23,14 @@ extern int max_send; /* Make sure we can't write a string past the end of the buffer */ -size_t srvstr_push_fn(const char *function, unsigned int line, +size_t srvstr_push_fn(const char *function, unsigned int line, const char *base_ptr, uint16 smb_flags2, void *dest, const char *src, int dest_len, int flags) { - size_t buf_used = PTR_DIFF(dest, base_ptr); - if (dest_len == -1) { - if (((ptrdiff_t)dest < (ptrdiff_t)base_ptr) || (buf_used > (size_t)max_send)) { -#if 0 - DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n")); -#endif - return push_string_fn(function, line, base_ptr, - smb_flags2, dest, src, -1, - flags); - } - return push_string_fn(function, line, base_ptr, smb_flags2, - dest, src, max_send - buf_used, flags); + if (dest_len < 0) { + return 0; } - + /* 'normal' push into size-specified buffer */ return push_string_fn(function, line, base_ptr, smb_flags2, dest, src, dest_len, flags); -- cgit