summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-06-21 05:38:28 +0000
committerAndrew Tridgell <tridge@samba.org>2001-06-21 05:38:28 +0000
commit4ff011d88ef5b79b92d2cea1abe32c93bc03f724 (patch)
tree20b1b8f8bebdb3b4f741f6f2733a23af01b7c467 /source3/libsmb
parentfda0f83d751a1ea6c731fd6a82484a724a1c6e32 (diff)
downloadsamba-4ff011d88ef5b79b92d2cea1abe32c93bc03f724.tar.gz
samba-4ff011d88ef5b79b92d2cea1abe32c93bc03f724.tar.bz2
samba-4ff011d88ef5b79b92d2cea1abe32c93bc03f724.zip
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)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/cliconnect.c6
-rw-r--r--source3/libsmb/clifile.c6
-rw-r--r--source3/libsmb/climessage.c11
-rw-r--r--source3/libsmb/clistr.c21
4 files changed, 30 insertions, 14 deletions
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 06f283c321..529aa0fef9 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -429,6 +429,12 @@ BOOL cli_negprot(struct cli_state *cli)
cli->readbraw_supported = True;
cli->writebraw_supported = True;
}
+ /* work out if they sent us a workgroup */
+ if (smb_buflen(cli->inbuf) > 8) {
+ clistr_pull(cli, cli->server_domain,
+ smb_buf(cli->inbuf)+8, sizeof(cli->server_domain),
+ smb_buflen(cli->inbuf)-8, STR_CONVERT|STR_UNICODE|STR_NOALIGN);
+ }
} else if (cli->protocol >= PROTOCOL_LANMAN1) {
cli->sec_mode = SVAL(cli->inbuf,smb_vwv1);
cli->max_xmit = SVAL(cli->inbuf,smb_vwv2);
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 4002a43c1b..42454b306f 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -243,7 +243,7 @@ int cli_nt_create_full(struct cli_state *cli, char *fname, uint32 DesiredAccess,
p = smb_buf(cli->outbuf);
/* this alignment and termination is critical for netapp filers. Don't change */
- p += clistr_align(cli->outbuf, p);
+ p += clistr_align(cli, p, STR_CONVERT);
len = clistr_push(cli, p, fname, -1, STR_CONVERT);
p += len;
SSVAL(cli->outbuf,smb_ntcreate_NameLength, len);
@@ -786,7 +786,7 @@ int cli_ctemp(struct cli_state *cli, char *path, char **tmp_path)
memset(cli->outbuf,'\0',smb_size);
memset(cli->inbuf,'\0',smb_size);
- set_message(cli->outbuf,1,strlen(path)+2,True);
+ set_message(cli->outbuf,1,0,True);
CVAL(cli->outbuf,smb_com) = SMBctemp;
SSVAL(cli->outbuf,smb_tid,cli->cnum);
@@ -798,6 +798,8 @@ int cli_ctemp(struct cli_state *cli, char *path, char **tmp_path)
*p++ = 4;
p += clistr_push(cli, p, path, -1, STR_TERMINATE | STR_CONVERT);
+ cli_setup_bcc(cli, p);
+
cli_send_smb(cli);
if (!cli_receive_smb(cli)) {
return -1;
diff --git a/source3/libsmb/climessage.c b/source3/libsmb/climessage.c
index 87f8175459..d46986bfd6 100644
--- a/source3/libsmb/climessage.c
+++ b/source3/libsmb/climessage.c
@@ -71,7 +71,7 @@ BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
char *p;
memset(cli->outbuf,'\0',smb_size);
- set_message(cli->outbuf,1,len+3,True);
+ set_message(cli->outbuf,1,0,True);
CVAL(cli->outbuf,smb_com) = SMBsendtxt;
SSVAL(cli->outbuf,smb_tid,cli->cnum);
cli_setup_packet(cli);
@@ -79,9 +79,12 @@ BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
SSVAL(cli->outbuf,smb_vwv0,grp);
p = smb_buf(cli->outbuf);
- *p = 1;
- SSVAL(p,1,len);
- memcpy(p+3,msg,len);
+ *p++ = 1;
+ SSVAL(p,0,len); p += 2;
+ memcpy(p,msg,len);
+ p += len;
+
+ cli_setup_bcc(cli, p);
cli_send_smb(cli);
if (!cli_receive_smb(cli)) {
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;
}