summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-12-06 17:16:33 -0800
committerJeremy Allison <jra@samba.org>2007-12-06 17:16:33 -0800
commit1b92ea5559bfa00016103508feac9a06ea4b66ae (patch)
treec11509a3fc07e7c828e1b40e4259f80d1fc0bf2e /source3/libsmb
parent9bd35ef153ef4b7f892dcf9e69c2232b940a9e18 (diff)
downloadsamba-1b92ea5559bfa00016103508feac9a06ea4b66ae.tar.gz
samba-1b92ea5559bfa00016103508feac9a06ea4b66ae.tar.bz2
samba-1b92ea5559bfa00016103508feac9a06ea4b66ae.zip
Remove pstrings from client/client.c by doing a large rewrite.
Mostly compiles.... Jeremy. (This used to be commit c87f3eba9aa52f4ab25d77e2167262bf5c43b1a6)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clidfs.c60
-rw-r--r--source3/libsmb/clifsinfo.c62
-rw-r--r--source3/libsmb/climessage.c46
-rw-r--r--source3/libsmb/clistr.c43
4 files changed, 117 insertions, 94 deletions
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 32a2c31c83..4cf37a250b 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -266,7 +266,8 @@ const char *cli_cm_get_mntpoint(struct cli_state *c)
********************************************************************/
static struct cli_state *cli_cm_connect(TALLOC_CTX *ctx,
- const char *server,
+ struct cli_state *referring_cli,
+ const char *server,
const char *share,
bool show_hdr)
{
@@ -289,8 +290,17 @@ static struct cli_state *cli_cm_connect(TALLOC_CTX *ctx,
cli_cm_set_mntpoint(node->cli, "");
- return node->cli;
+ if (referring_cli && referring_cli->posix_capabilities) {
+ uint16 major, minor;
+ uint32 caplow, caphigh;
+ if (cli_unix_extensions_version(cli, &major,
+ &minor, &caplow, &caphigh)) {
+ cli_set_unix_extensions_capabilities(cli, major, minor,
+ caplow, caphigh);
+ }
+ }
+ return node->cli;
}
/********************************************************************
@@ -317,6 +327,7 @@ static struct cli_state *cli_cm_find(const char *server, const char *share)
****************************************************************************/
struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
+ struct cli_state *referring_cli,
const char *server,
const char *share,
bool show_hdr)
@@ -327,7 +338,7 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
c = cli_cm_find(server, share);
if (!c) {
- c = cli_cm_connect(ctx, server, share, show_hdr);
+ c = cli_cm_connect(ctx, referring_cli, server, share, show_hdr);
}
return c;
@@ -378,17 +389,17 @@ static void cm_set_password(const char *newpass)
}
}
-void cli_cm_set_credentials(struct user_auth_info *user)
+void cli_cm_set_credentials(void)
{
SAFE_FREE(cm_creds.username);
- cm_creds.username = SMB_STRDUP(user->username);
+ cm_creds.username = SMB_STRDUP(get_cmdline_auth_info_username());
- if (user->got_pass) {
- cm_set_password(user->password);
+ if (get_cmdline_auth_info_got_pass()) {
+ cm_set_password(get_cmdline_auth_info_password());
}
- cm_creds.use_kerberos = user->use_kerberos;
- cm_creds.signing_state = user->signing_state;
+ cm_creds.use_kerberos = get_cmdline_auth_info_use_kerberos();
+ cm_creds.signing_state = get_cmdline_auth_info_signing_state();
}
/****************************************************************************
@@ -729,7 +740,8 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
/* Check for the referral. */
- if (!(cli_ipc = cli_cm_open(ctx, rootcli->desthost, "IPC$", false))) {
+ if (!(cli_ipc = cli_cm_open(ctx, rootcli,
+ rootcli->desthost, "IPC$", false))) {
return false;
}
@@ -768,7 +780,8 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
*/
/* Open the connection to the target server & share */
- if ((*targetcli = cli_cm_open(ctx, server, share, false)) == NULL) {
+ if ((*targetcli = cli_cm_open(ctx, rootcli,
+ server, share, false)) == NULL) {
d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
server, share );
return false;
@@ -853,31 +866,6 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
}
/********************************************************************
- Temporary hack - remove when pstring is dead. JRA.
-********************************************************************/
-
-bool cli_resolve_path_pstring( const char *mountpt,
- struct cli_state *rootcli,
- const char *path,
- struct cli_state **targetcli,
- pstring targetpath)
-{
- char *tpath = NULL;
- TALLOC_CTX *ctx = talloc_stackframe();
- bool ret = cli_resolve_path(ctx,
- mountpt,
- rootcli,
- path,
- targetcli,
- &tpath);
- if (tpath) {
- pstrcpy(targetpath, tpath);
- }
- TALLOC_FREE(ctx);
- return ret;
-}
-
-/********************************************************************
********************************************************************/
bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
diff --git a/source3/libsmb/clifsinfo.c b/source3/libsmb/clifsinfo.c
index a45623b9e4..1a75d144b2 100644
--- a/source3/libsmb/clifsinfo.c
+++ b/source3/libsmb/clifsinfo.c
@@ -22,7 +22,7 @@
/****************************************************************************
Get UNIX extensions version info.
****************************************************************************/
-
+
bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *pminor,
uint32 *pcaplow, uint32 *pcaphigh)
{
@@ -33,18 +33,18 @@ bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *
unsigned int rparam_count=0, rdata_count=0;
setup = TRANSACT2_QFSINFO;
-
+
SSVAL(param,0,SMB_QUERY_CIFS_UNIX_INFO);
- if (!cli_send_trans(cli, SMBtrans2,
- NULL,
+ if (!cli_send_trans(cli, SMBtrans2,
+ NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
-
+
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@@ -67,7 +67,7 @@ bool cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *
cli->posix_capabilities = *pcaplow = IVAL(rdata,4);
*pcaphigh = IVAL(rdata,8);
- /* todo: but not yet needed
+ /* todo: but not yet needed
* return the other stuff
*/
@@ -75,13 +75,13 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
- return ret;
+ return ret;
}
/****************************************************************************
Set UNIX extensions capabilities.
****************************************************************************/
-
+
bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, uint16 minor,
uint32 caplow, uint32 caphigh)
{
@@ -93,7 +93,7 @@ bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, u
unsigned int rparam_count=0, rdata_count=0;
setup = TRANSACT2_SETFSINFO;
-
+
SSVAL(param,0,0);
SSVAL(param,2,SMB_SET_CIFS_UNIX_INFO);
@@ -102,15 +102,15 @@ bool cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, u
SIVAL(data,4,caplow);
SIVAL(data,8,caphigh);
- if (!cli_send_trans(cli, SMBtrans2,
- NULL,
+ if (!cli_send_trans(cli, SMBtrans2,
+ NULL,
0, 0,
&setup, 1, 0,
param, 4, 0,
data, 12, 560)) {
goto cleanup;
}
-
+
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@@ -128,7 +128,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
- return ret;
+ return ret;
}
bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
@@ -143,18 +143,18 @@ bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
smb_panic("cli_get_fs_attr_info() called with NULL Pionter!");
setup = TRANSACT2_QFSINFO;
-
+
SSVAL(param,0,SMB_QUERY_FS_ATTRIBUTE_INFO);
- if (!cli_send_trans(cli, SMBtrans2,
- NULL,
+ if (!cli_send_trans(cli, SMBtrans2,
+ NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
-
+
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@@ -174,7 +174,7 @@ bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
*fs_attr = IVAL(rdata,0);
- /* todo: but not yet needed
+ /* todo: but not yet needed
* return the other stuff
*/
@@ -182,7 +182,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
- return ret;
+ return ret;
}
bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint32 *pserial_number)
@@ -195,18 +195,18 @@ bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint
unsigned char nlen;
setup = TRANSACT2_QFSINFO;
-
+
SSVAL(param,0,SMB_INFO_VOLUME);
- if (!cli_send_trans(cli, SMBtrans2,
- NULL,
+ if (!cli_send_trans(cli, SMBtrans2,
+ NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
-
+
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@@ -230,7 +230,7 @@ bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint
nlen = CVAL(rdata,l2_vol_cch);
clistr_pull(cli, volume_name, rdata + l2_vol_szVolLabel, sizeof(fstring), nlen, STR_NOALIGN);
- /* todo: but not yet needed
+ /* todo: but not yet needed
* return the other stuff
*/
@@ -238,7 +238,7 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
- return ret;
+ return ret;
}
bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *pserial_number, time_t *pdate)
@@ -251,18 +251,18 @@ bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *
unsigned int nlen;
setup = TRANSACT2_QFSINFO;
-
+
SSVAL(param,0,SMB_QUERY_FS_VOLUME_INFO);
- if (!cli_send_trans(cli, SMBtrans2,
- NULL,
+ if (!cli_send_trans(cli, SMBtrans2,
+ NULL,
0, 0,
&setup, 1, 0,
param, 2, 0,
NULL, 0, 560)) {
goto cleanup;
}
-
+
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, &rparam_count,
&rdata, &rdata_count)) {
@@ -291,7 +291,7 @@ bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *
nlen = IVAL(rdata,12);
clistr_pull(cli, volume_name, rdata + 18, sizeof(fstring), nlen, STR_UNICODE);
- /* todo: but not yet needed
+ /* todo: but not yet needed
* return the other stuff
*/
@@ -299,5 +299,5 @@ cleanup:
SAFE_FREE(rparam);
SAFE_FREE(rdata);
- return ret;
+ return ret;
}
diff --git a/source3/libsmb/climessage.c b/source3/libsmb/climessage.c
index 2a195753ae..13ef1d43d4 100644
--- a/source3/libsmb/climessage.c
+++ b/source3/libsmb/climessage.c
@@ -19,11 +19,11 @@
#include "includes.h"
-
/****************************************************************************
-start a message sequence
+ Start a message sequence.
****************************************************************************/
-int cli_message_start_build(struct cli_state *cli, char *host, char *username)
+
+int cli_message_start_build(struct cli_state *cli, const char *host, const char *username)
{
char *p;
@@ -33,25 +33,26 @@ int cli_message_start_build(struct cli_state *cli, char *host, char *username)
SCVAL(cli->outbuf,smb_com,SMBsendstrt);
SSVAL(cli->outbuf,smb_tid,cli->cnum);
cli_setup_packet(cli);
-
+
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, username, -1, STR_ASCII|STR_TERMINATE);
+ p += clistr_push(cli, p, username,
+ cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
*p++ = 4;
- p += clistr_push(cli, p, host, -1, STR_ASCII|STR_TERMINATE);
-
+ p += clistr_push(cli, p, host,
+ cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
+
cli_setup_bcc(cli, p);
return(PTR_DIFF(p, cli->outbuf));
}
-bool cli_message_start(struct cli_state *cli, char *host, char *username,
+bool cli_message_start(struct cli_state *cli, const char *host, const char *username,
int *grp)
{
cli_message_start_build(cli, host, username);
-
- cli_send_smb(cli);
-
+ cli_send_smb(cli);
+
if (!cli_receive_smb(cli)) {
return False;
}
@@ -63,11 +64,11 @@ bool cli_message_start(struct cli_state *cli, char *host, char *username,
return True;
}
-
/****************************************************************************
-send a message
+ Send a message
****************************************************************************/
-int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
+
+int cli_message_text_build(struct cli_state *cli, const char *msg, int len, int grp)
{
char *msgdos;
int lendos;
@@ -80,17 +81,23 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
cli_setup_packet(cli);
SSVAL(cli->outbuf,smb_vwv0,grp);
-
+
p = smb_buf(cli->outbuf);
*p++ = 1;
if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **)(void *)&msgdos, True)) < 0 || !msgdos) {
DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
SSVAL(p, 0, len); p += 2;
+ if (len > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
+ return -1;
+ }
memcpy(p, msg, len);
p += len;
} else {
SSVAL(p, 0, lendos); p += 2;
+ if (lendos > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
+ return -1;
+ }
memcpy(p, msgdos, lendos);
p += lendos;
SAFE_FREE(msgdos);
@@ -101,7 +108,7 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
return(PTR_DIFF(p, cli->outbuf));
}
-bool cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
+bool cli_message_text(struct cli_state *cli, const char *msg, int len, int grp)
{
cli_message_text_build(cli, msg, len, grp);
@@ -114,11 +121,12 @@ bool cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
if (cli_is_error(cli)) return False;
return True;
-}
+}
/****************************************************************************
-end a message
+ End a message.
****************************************************************************/
+
int cli_message_end_build(struct cli_state *cli, int grp)
{
char *p;
@@ -150,4 +158,4 @@ bool cli_message_end(struct cli_state *cli, int grp)
if (cli_is_error(cli)) return False;
return True;
-}
+}
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)
{