summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-03-14 12:42:43 +0000
committerAndrew Tridgell <tridge@samba.org>2001-03-14 12:42:43 +0000
commit9ea70bd00349bc391809bec374700c6d9ce2952b (patch)
tree4a5aeb71abe62792cb9fa9c03feaa6f2401e6272 /source3/libsmb
parent376a44c81d360026eb0c2886e9a05dd2bfefd2cc (diff)
downloadsamba-9ea70bd00349bc391809bec374700c6d9ce2952b.tar.gz
samba-9ea70bd00349bc391809bec374700c6d9ce2952b.tar.bz2
samba-9ea70bd00349bc391809bec374700c6d9ce2952b.zip
simpler clistr interface which handles individual packets having
unicode bit set differently to capabilities (This used to be commit 34a0821e087810381996f5ff6cf3b4d7b9bb53a0)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c2
-rw-r--r--source3/libsmb/clilist.c16
-rw-r--r--source3/libsmb/clistr.c52
-rw-r--r--source3/libsmb/clitrans.c8
4 files changed, 18 insertions, 60 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 8742a576cf..79a168121b 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -198,7 +198,7 @@ int cli_nt_create(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, PTR_DIFF(p, cli->outbuf));
+ p += clistr_align(cli->outbuf, p);
len = clistr_push(cli, p, fname, -1, STR_CONVERT);
p += len;
SSVAL(cli->outbuf,smb_ntcreate_NameLength, len);
diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
index f0ca0d5f54..0033f05942 100644
--- a/source3/libsmb/clilist.c
+++ b/source3/libsmb/clilist.c
@@ -194,10 +194,6 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
break;
}
- param_len = 12+clistr_push_size(cli, NULL, mask, -1,
- STR_TERMINATE |
- STR_CONVERT);
-
if (First) {
setup = TRANSACT2_FINDFIRST;
SSVAL(param,0,attribute); /* attribute */
@@ -205,8 +201,9 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
SSVAL(param,4,4+2); /* resume required + close on end */
SSVAL(param,6,info_level);
SIVAL(param,8,0);
- clistr_push(cli, param+12, mask, -1,
- STR_TERMINATE | STR_CONVERT);
+ p = param+12;
+ p += clistr_push(cli, param+12, mask, -1,
+ STR_TERMINATE | STR_CONVERT);
} else {
setup = TRANSACT2_FINDNEXT;
SSVAL(param,0,ff_dir_handle);
@@ -214,10 +211,13 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
SSVAL(param,4,info_level);
SIVAL(param,6,0); /* ff_resume_key */
SSVAL(param,10,8+4+2); /* continue + resume required + close on end */
- clistr_push(cli, param+12, mask, -1,
- STR_TERMINATE | STR_CONVERT);
+ p = param+12;
+ p += clistr_push(cli, param+12, mask, -1,
+ STR_TERMINATE | STR_CONVERT);
}
+ param_len = PTR_DIFF(p, param);
+
if (!cli_send_trans(cli, SMBtrans2,
NULL, /* Name */
-1, 0, /* fid, flags */
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;
}
diff --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c
index 0bbe7c6dae..d21d179126 100644
--- a/source3/libsmb/clitrans.c
+++ b/source3/libsmb/clitrans.c
@@ -51,9 +51,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
cli_setup_packet(cli);
if (pipe_name) {
- pipe_name_len = clistr_push_size(cli, smb_buf(cli->outbuf),
- pipe_name, -1,
- STR_TERMINATE);
+ pipe_name_len = clistr_push(cli, smb_buf(cli->outbuf), pipe_name, -1, STR_TERMINATE);
}
outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len : 3);
@@ -75,9 +73,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
for (i=0;i<lsetup;i++) /* setup[] */
SSVAL(cli->outbuf,smb_setup+i*2,setup[i]);
p = smb_buf(cli->outbuf);
- if (trans==SMBtrans) {
- clistr_push(cli, p, pipe_name, -1, STR_TERMINATE);
- } else {
+ if (trans != SMBtrans) {
*p++ = 0; /* put in a null smb_name */
*p++ = 'D'; *p++ = ' '; /* observed in OS/2 */
}