extern int DEBUGLEVEL;
+/*
+ * set the port that will be used for connections by the client
+ */
+
+int cli_set_port(struct cli_state *cli, int port)
+{
+
+ if (port != 0)
+ cli -> port = port;
+
+ return cli -> port; /* return it incase caller wants it */
+
+}
+
+/****************************************************************************
+recv an smb
+****************************************************************************/
+static BOOL cli_receive_smb(struct cli_state *cli)
+{
+ return client_receive_smb(cli->fd,cli->inbuf,cli->timeout);
+}
/****************************************************************************
send an smb to a fd and re-establish if necessary
****************************************************************************/
-static BOOL cli_send_smb(struct cli_state *cli)
+static BOOL cli_send_smb(struct cli_state *cli, BOOL show)
{
size_t len;
size_t nwritten=0;
ssize_t ret;
BOOL reestablished=False;
+ if (show)
+ {
+ show_msg(cli->outbuf);
+ }
+
len = smb_len(cli->outbuf) + 4;
while (nwritten < len) {
ret = write_socket(cli->fd,cli->outbuf+nwritten,len - nwritten);
- if (ret <= 0 && errno == EPIPE && !reestablished) {
+ if (ret <= 0 && errno == EPIPE && !reestablished)
+ {
+ DEBUG(5,("cli_send_smb: write error (%s) - reconnecting\n",
+ strerror(errno)));
+
if (cli_reestablish_connection(cli)) {
reestablished = True;
nwritten=0;
if (ret <= 0) {
DEBUG(0,("Error writing %d bytes to client. %d. Exiting\n",
len,ret));
- close_sockets();
- exit(1);
+ return False;
}
nwritten += ret;
}
set_message(cli->outbuf,14+lsetup, /* wcnt, bcc */
PTR_DIFF(outdata+this_ldata,smb_buf(cli->outbuf)),False);
- show_msg(cli->outbuf);
- cli_send_smb(cli);
+ cli_send_smb(cli, True);
if (this_ldata < ldata || this_lparam < lparam) {
/* receive interim response */
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout) ||
+ if (!cli_receive_smb(cli) ||
CVAL(cli->inbuf,smb_rcls) != 0) {
return(False);
}
set_message(cli->outbuf,trans==SMBtrans?8:9, /* wcnt, bcc */
PTR_DIFF(outdata+this_ldata,smb_buf(cli->outbuf)),False);
- show_msg(cli->outbuf);
- cli_send_smb(cli);
+ cli_send_smb(cli, True);
tot_data += this_ldata;
tot_param += this_lparam;
int total_data=0;
int total_param=0;
int this_data,this_param;
+ uint8 eclass;
+ uint32 num;
*data_len = *param_len = 0;
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ if (!cli_receive_smb(cli))
return False;
- show_msg(cli->inbuf);
-
/* sanity check */
if (CVAL(cli->inbuf,smb_com) != trans) {
DEBUG(0,("Expected %s response, got command 0x%02x\n",
return(False);
}
- if (cli_error(cli, NULL, NULL))
+ /* DOS error "more data" is an acceptable error code */
+ if (cli_error(cli, &eclass, &num) && !(eclass == ERRDOS && num == ERRmoredata))
{
return(False);
}
if (total_data <= *data_len && total_param <= *param_len)
break;
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ if (!cli_receive_smb(cli))
return False;
- show_msg(cli->inbuf);
-
/* sanity check */
if (CVAL(cli->inbuf,smb_com) != trans) {
DEBUG(0,("Expected %s response, got command 0x%02x\n",
CVAL(cli->inbuf,smb_com)));
return(False);
}
- if (cli_error(cli, NULL, NULL))
+ /* DOS error "more data" is an acceptable error code */
+ if (cli_error(cli, &eclass, &num) && eclass != ERRDOS && num != ERRmoredata)
{
return(False);
}
fstring pword, ntpword;
if (cli->protocol < PROTOCOL_LANMAN1)
+ {
return True;
+ }
- if (passlen > sizeof(pword)-1 || ntpasslen > sizeof(ntpword)-1) {
+ if (passlen > sizeof(pword)-1 || ntpasslen > sizeof(ntpword)-1)
+ {
return False;
}
- if (((passlen == 0) || (passlen == 1)) && (pass[0] == '\0')) {
- /* Null session connect. */
- pword[0] = '\0';
- ntpword[0] = '\0';
- } else {
- if ((cli->sec_mode & 2) && passlen != 24) {
- passlen = 24;
- ntpasslen = 24;
- SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
- SMBNTencrypt((uchar *)ntpass,(uchar *)cli->cryptkey,(uchar *)ntpword);
- } else {
- fstrcpy(pword, pass);
- fstrcpy(ntpword, "");
- ntpasslen = 0;
- }
- }
-
- /* if in share level security then don't send a password now */
- if (!(cli->sec_mode & 1)) {
+ if (!IS_BITS_SET_ALL(cli->sec_mode, 1))
+ {
+ /* if in share level security then don't send a password now */
fstrcpy(pword, "");
passlen=1;
fstrcpy(ntpword, "");
ntpasslen=1;
}
+ else if ((passlen == 0 || passlen == 1) && (pass[0] == '\0'))
+ {
+ /* Null session connect. */
+ pword [0] = '\0';
+ ntpword[0] = '\0';
+ }
+ else if (passlen == 24 && ntpasslen == 24)
+ {
+ if (IS_BITS_SET_ALL(cli->sec_mode, 2))
+ {
+ /* encrypted password, implicit from 24-byte lengths */
+ memcpy(pword , pass , 24);
+ memcpy(ntpword, ntpass, 24);
+ }
+ else
+ {
+ DEBUG(0,("cli_session_setup: encrypted passwords not supported by server\n"));
+ return False;
+ }
+ }
+ else if (ntpasslen == 0 || !IS_BITS_SET_ALL(cli->sec_mode, 2))
+ {
+ /* plain-text password: server doesn't support encrypted. */
+ fstrcpy(pword, pass);
+ fstrcpy(ntpword, "");
+ ntpasslen = 0;
+ }
+ else /* passlen != 0 && ntpasslen != 0 && server supports encryption */
+ {
+ /* plain-text password requesting to be encrypted */
+ uchar *key = (uchar *)cli->cryptkey;
+ SMBencrypt ((uchar *)pass , key,(uchar *)pword );
+ SMBNTencrypt((uchar *)ntpass, key,(uchar *)ntpword);
+ passlen = 24;
+ ntpasslen = 24;
+ }
/* send a session setup command */
bzero(cli->outbuf,smb_size);
set_message(cli->outbuf,13,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
}
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli))
+ {
+ DEBUG(10,("cli_session_setup: receive smb failed\n"));
return False;
-
- show_msg(cli->inbuf);
+ }
if (CVAL(cli->inbuf,smb_rcls) != 0) {
return False;
/* use the returned vuid from now on */
cli->vuid = SVAL(cli->inbuf,smb_uid);
+ if (cli->protocol >= PROTOCOL_NT1) {
+ /*
+ * Save off some of the connected server
+ * info.
+ */
+ char *server_domain,*server_os,*server_type;
+ server_os = smb_buf(cli->inbuf);
+ server_type = skip_string(server_os,1);
+ server_domain = skip_string(server_type,1);
+ fstrcpy(cli->server_os, server_os);
+ fstrcpy(cli->server_type, server_type);
+ fstrcpy(cli->server_domain, server_domain);
+ }
+
fstrcpy(cli->user_name, user);
return True;
SSVAL(cli->outbuf,smb_vwv0,0xFF);
SSVAL(cli->outbuf,smb_vwv2,0); /* no additional info */
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli))
return False;
return CVAL(cli->inbuf,smb_rcls) == 0;
slprintf(fullshare, sizeof(fullshare)-1,
"\\\\%s\\%s", cli->desthost, share);
+ strupper(fullshare);
set_message(cli->outbuf,4,
2 + strlen(fullshare) + passlen + strlen(dev),True);
SCVAL(cli->inbuf,smb_rcls, 1);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli))
return False;
if (CVAL(cli->inbuf,smb_rcls) != 0) {
SSVAL(cli->outbuf,smb_tid,cli->cnum);
cli_setup_packet(cli);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli))
return False;
return CVAL(cli->inbuf,smb_rcls) == 0;
*p++ = 4;
pstrcpy(p,fname_dst);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
*p++ = 4;
pstrcpy(p,fname);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
*p++ = 4;
pstrcpy(p,dname);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
*p++ = 4;
pstrcpy(p,dname);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
pstrcpy(p,fname);
p = skip_string(p,1);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return -1;
}
/* you must open for RW not just write - otherwise getattrE doesn't
work! */
- if ((flags & O_ACCMODE) == O_WRONLY) {
+ if ((flags & O_ACCMODE) == O_WRONLY && strncmp(cli->dev, "LPT", 3)) {
flags = (flags & ~O_ACCMODE) | O_RDWR;
}
pstrcpy(p,fname);
p = skip_string(p,1);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return -1;
}
SSVAL(cli->outbuf,smb_vwv0,fnum);
SIVALS(cli->outbuf,smb_vwv1,-1);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
SSVAL(p, 0, cli->pid);
SIVAL(p, 2, offset);
SIVAL(p, 6, len);
- cli_send_smb(cli);
+ cli_send_smb(cli, True);
cli->timeout = (timeout == -1) ? 0x7FFFFFFF : timeout;
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ if (!cli_receive_smb(cli)) {
cli->timeout = saved_timeout;
return False;
}
SIVAL(p, 2, offset);
SIVAL(p, 6, len);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
SSVAL(cli->outbuf,smb_vwv6,size);
SSVAL(cli->outbuf,smb_mid,cli->mid + i);
- cli_send_smb(cli);
+ cli_send_smb(cli, True);
}
/****************************************************************************
issued++;
}
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ if (!cli_receive_smb(cli)) {
return total;
}
}
while (received < issued) {
- client_receive_smb(cli->fd,cli->inbuf,cli->timeout);
+ cli_receive_smb(cli);
received++;
}
SSVAL(cli->outbuf,smb_mid,cli->mid + i);
- show_msg(cli->outbuf);
- cli_send_smb(cli);
+ cli_send_smb(cli, True);
}
/****************************************************************************
0x0008 start of message mode named pipe protocol
****************************************************************************/
ssize_t cli_write(struct cli_state *cli,
- int fnum, uint16 write_mode,
- char *buf, off_t offset, size_t size)
+ int fnum, uint16 write_mode,
+ char *buf, off_t offset, size_t size)
{
int total = -1;
int issued=0;
issued++;
}
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ if (!cli_receive_smb(cli)) {
return total;
}
}
while (received < issued) {
- client_receive_smb(cli->fd,cli->inbuf,cli->timeout);
+ cli_receive_smb(cli);
received++;
}
do a SMBgetattrE call
****************************************************************************/
BOOL cli_getattrE(struct cli_state *cli, int fd,
- uint32 *attr, size_t *size,
+ uint16 *attr, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time)
{
bzero(cli->outbuf,smb_size);
SSVAL(cli->outbuf,smb_vwv0,fd);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
do a SMBgetatr call
****************************************************************************/
BOOL cli_getatr(struct cli_state *cli, char *fname,
- uint32 *attr, size_t *size, time_t *t)
+ uint16 *attr, size_t *size, time_t *t)
{
char *p;
*p = 4;
pstrcpy(p+1, fname);
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
/****************************************************************************
do a SMBsetatr call
****************************************************************************/
-BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t)
+BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t)
{
char *p;
p = skip_string(p,1);
*p = 4;
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
return False;
}
****************************************************************************/
BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
- size_t *size, uint32 *mode)
+ size_t *size, uint16 *mode)
{
int data_len = 0;
int param_len = 0;
****************************************************************************/
BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
- time_t *w_time, size_t *size, uint32 *mode)
+ time_t *w_time, size_t *size, uint16 *mode,
+ SMB_INO_T *ino)
{
int data_len = 0;
int param_len = 0;
if (w_time) {
*w_time = interpret_long_date(rdata+24) - cli->serverzone;
}
+ if (mode) {
+ *mode = SVAL(rdata, 32);
+ }
if (size) {
*size = IVAL(rdata, 40);
}
- if (mode) {
- *mode = IVAL(rdata, 32);
+ if (ino) {
+ *ino = IVAL(rdata, 64);
}
if (rdata) free(rdata);
send a qfileinfo call
****************************************************************************/
BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
- uint32 *mode, size_t *size,
- time_t *c_time, time_t *a_time, time_t *m_time)
+ uint16 *mode, size_t *size,
+ time_t *c_time, time_t *a_time, time_t *m_time,
+ time_t *w_time, SMB_INO_T *ino)
{
int data_len = 0;
int param_len = 0;
pstring param;
char *rparam=NULL, *rdata=NULL;
+ /* if its a win95 server then fail this - win95 totally screws it
+ up */
+ if (cli->win95) return False;
+
param_len = 4;
memset(param, 0, param_len);
SSVAL(param, 0, fnum);
- SSVAL(param, 2, SMB_INFO_STANDARD);
+ SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
if (!cli_send_trans(cli, SMBtrans2,
NULL, 0, /* name, length */
return False;
}
- if (!rdata || data_len < 22) {
+ if (!rdata || data_len < 68) {
return False;
}
if (c_time) {
- *c_time = make_unix_date2(rdata+0);
+ *c_time = interpret_long_date(rdata+0) - cli->serverzone;
}
if (a_time) {
- *a_time = make_unix_date2(rdata+4);
+ *a_time = interpret_long_date(rdata+8) - cli->serverzone;
}
if (m_time) {
- *m_time = make_unix_date2(rdata+8);
+ *m_time = interpret_long_date(rdata+16) - cli->serverzone;
}
- if (size) {
- *size = IVAL(rdata, 12);
+ if (w_time) {
+ *w_time = interpret_long_date(rdata+24) - cli->serverzone;
}
if (mode) {
- *mode = SVAL(rdata,l1_attrFile);
+ *mode = SVAL(rdata, 32);
+ }
+ if (size) {
+ *size = IVAL(rdata, 40);
+ }
+ if (ino) {
+ *ino = IVAL(rdata, 64);
}
if (rdata) free(rdata);
/****************************************************************************
do a directory listing, calling fn on each file found
****************************************************************************/
-int cli_list(struct cli_state *cli,char *Mask,int attribute,void (*fn)(file_info *))
+int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
+ void (*fn)(file_info *, const char *))
{
int max_matches = 512;
/* NT uses 260, OS/2 uses 2. Both accept 1. */
for (p=dirlist,i=0;i<total_received;i++) {
p += interpret_long_filename(info_level,p,&finfo);
- fn(&finfo);
+ fn(&finfo, Mask);
}
/* free up the dirlist buffer */
Send a SamOEMChangePassword command
****************************************************************************/
-BOOL cli_oem_change_password(struct cli_state *cli, char *user, char *new_password,
- char *old_password)
+BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
+ const char *old_password)
{
char param[16+sizeof(fstring)];
char data[532];
data_len = 532;
- if (cli_send_trans(cli,SMBtrans,
+ if (!cli_send_trans(cli,SMBtrans,
PIPE_LANMAN,strlen(PIPE_LANMAN), /* name, length */
0,0, /* fid, flags */
NULL,0,0, /* setup, length, max */
param,param_len,2, /* param, length, max */
data,data_len,0 /* data, length, max */
- ) == False) {
+ ))
+ {
DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
user ));
return False;
CVAL(smb_buf(cli->outbuf),0) = 2;
- cli_send_smb(cli);
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli))
+ {
return False;
-
- show_msg(cli->inbuf);
+ }
if (CVAL(cli->inbuf,smb_rcls) != 0 ||
((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {
retry:
#endif /* WITH_SSL */
- cli_send_smb(cli);
+ cli_send_smb(cli, False);
DEBUG(5,("Sent session request\n"));
- if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
+ if (!cli_receive_smb(cli))
return False;
#ifdef WITH_SSL
/****************************************************************************
open the client sockets
****************************************************************************/
-BOOL cli_connect(struct cli_state *cli, char *host, struct in_addr *ip)
+BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
{
extern struct in_addr ipzero;
}
+ if (cli -> port == 0) cli -> port = 139;
+
cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
- 139, cli->timeout);
+ cli -> port, cli->timeout);
if (cli->fd == -1)
return False;
/****************************************************************************
initialise a client structure
****************************************************************************/
-BOOL cli_initialise(struct cli_state *cli)
+struct cli_state *cli_initialise(struct cli_state *cli)
{
- if (cli->initialised)
- {
+ if (!cli) {
+ cli = (struct cli_state *)malloc(sizeof(*cli));
+ if (!cli)
+ return NULL;
+ ZERO_STRUCTP(cli);
+ }
+
+ if (cli->initialised) {
cli_shutdown(cli);
}
- memset(cli, 0, sizeof(*cli));
+ ZERO_STRUCTP(cli);
+ cli -> port = 0;
cli->fd = -1;
cli->cnum = -1;
cli->pid = (uint16)getpid();
cli->initialised = 1;
- return True;
+ return cli;
}
/****************************************************************************
****************************************************************************/
void cli_shutdown(struct cli_state *cli)
{
+ DEBUG(10,("cli_shutdown\n"));
if (cli->outbuf)
{
free(cli->outbuf);
sslutil_disconnect(cli->fd);
#endif /* WITH_SSL */
if (cli->fd != -1)
- close(cli->fd);
+ {
+ close(cli->fd);
+ }
memset(cli, 0, sizeof(*cli));
}
****************************************************************************/
int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num)
{
- int flgs2 = SVAL(cli->inbuf,smb_flg2);
+ int flgs2;
char rcls;
int code;
+ if (!cli->initialised)
+ {
+ DEBUG(0,("cli_error: client state uninitialised!\n"));
+ return EINVAL;
+ }
+
+ flgs2 = SVAL(cli->inbuf,smb_flg2);
+
if (eclass) *eclass = 0;
if (num ) *num = 0;
case ERRnoaccess: return EACCES;
case ERRfilexists: return EEXIST;
case ERRrename: return EEXIST;
+ case ERRbadshare: return EBUSY;
+ case ERRlock: return EBUSY;
}
}
if (rcls == ERRSRV) {
switch (code) {
case ERRbadpw: return EPERM;
+ case ERRaccess: return EACCES;
+ case ERRnoresource: return ENOMEM;
+ case ERRinvdevice: return ENODEV;
+ case ERRinvnetname: return ENODEV;
}
}
/* for other cases */
fstrcpy(dest_host, cli->full_dest_host_name);
DEBUG(5,("cli_reestablish_connection: %s connecting to %s (ip %s) - %s [%s]\n",
- namestr(&calling), namestr(&called),
+ nmb_namestr(&calling), nmb_namestr(&called),
inet_ntoa(cli->dest_ip),
cli->user_name, cli->domain));
BOOL do_shutdown, BOOL do_tcon)
{
DEBUG(5,("cli_establish_connection: %s connecting to %s (%s) - %s [%s]\n",
- namestr(calling), namestr(called), inet_ntoa(*dest_ip),
+ nmb_namestr(calling), nmb_namestr(called), inet_ntoa(*dest_ip),
cli->user_name, cli->domain));
/* establish connection */
if (!cli_connect(cli, dest_host, dest_ip))
{
DEBUG(1,("cli_establish_connection: failed to connect to %s (%s)\n",
- namestr(calling), inet_ntoa(*dest_ip)));
+ nmb_namestr(calling), inet_ntoa(*dest_ip)));
return False;
}
}
{
DEBUG(1,("failed session setup\n"));
if (do_shutdown)
- cli_shutdown(cli);
+ {
+ cli_shutdown(cli);
+ }
return False;
}
{
DEBUG(1,("failed tcon_X\n"));
if (do_shutdown)
- cli_shutdown(cli);
+ {
+ cli_shutdown(cli);
+ }
return False;
}
}
}
if (do_shutdown)
- cli_shutdown(cli);
+ {
+ cli_shutdown(cli);
+ }
return True;
}
+/****************************************************************************
+ connect to one of multiple servers: don't care which
+****************************************************************************/
+BOOL cli_connect_serverlist(struct cli_state *cli, char *p)
+{
+ extern pstring global_myname;
+ extern pstring scope;
+ fstring remote_machine;
+ struct in_addr dest_ip;
+ struct nmb_name calling, called, stupid_smbserver_called;
+ BOOL connected_ok = False;
+
+ /*
+ * Treat each name in the 'password server =' line as a potential
+ * PDC/BDC. Contact each in turn and try and authenticate.
+ */
+
+ while(p && next_token(&p,remote_machine,LIST_SEP,sizeof(remote_machine)))
+ {
+ ZERO_STRUCTP(cli);
+
+ if (!cli_initialise(cli))
+ {
+ DEBUG(0,("cli_connect_serverlist: unable to initialize client connection.\n"));
+ return False;
+ }
+
+ standard_sub_basic(remote_machine);
+ strupper(remote_machine);
+
+ if (!resolve_name( remote_machine, &dest_ip, 0x20))
+ {
+ DEBUG(1,("cli_connect_serverlist: Can't resolve address for %s\n", remote_machine));
+ continue;
+ }
+
+ if ((lp_security() != SEC_USER) && (ismyip(dest_ip)))
+ {
+ DEBUG(1,("cli_connect_serverlist: Password server loop - not using password server %s\n", remote_machine));
+ continue;
+ }
+
+ make_nmb_name(&calling, global_myname , 0x0 , scope);
+ make_nmb_name(&called , remote_machine, 0x20, scope);
+ /* stupid microsoft destruction of the ability of netbios
+ * to provide multiple netbios servers on one host.
+ */
+ make_nmb_name(&stupid_smbserver_called , "*SMBSERVER", 0x20, scope);
+
+ pwd_set_nullpwd(&cli->pwd);
+
+ if (!cli_establish_connection(cli, remote_machine, &dest_ip,
+ &calling, &called,
+ "IPC$", "IPC",
+ False, True) &&
+ !cli_establish_connection(cli, remote_machine, &dest_ip,
+ &calling, &stupid_smbserver_called,
+ "IPC$", "IPC",
+ False, True))
+ {
+ cli_shutdown(cli);
+ continue;
+ }
+
+ if (cli->protocol < PROTOCOL_LANMAN2 ||
+ !IS_BITS_SET_ALL(cli->sec_mode, 1))
+ {
+ DEBUG(1,("cli_connect_serverlist: machine %s isn't in user level security mode\n",
+ remote_machine));
+ cli_shutdown(cli);
+ continue;
+ }
+
+ /*
+ * We have an anonymous connection to IPC$.
+ */
+
+ connected_ok = True;
+ break;
+ }
+
+ if (!connected_ok)
+ {
+ DEBUG(0,("cli_connect_serverlist: Domain password server not available.\n"));
+ cli_shutdown(cli);
+ }
+
+ return connected_ok;
+}
+
/****************************************************************************
cancel a print job
****************************************************************************/
return i;
}
+
+/****************************************************************************
+check for existance of a dir
+****************************************************************************/
+BOOL cli_chkpath(struct cli_state *cli, char *path)
+{
+ fstring path2;
+ char *p;
+
+ fstrcpy(path2,path);
+ trim_string(path2,NULL,"\\");
+ if (!*path2) *path2 = '\\';
+
+ bzero(cli->outbuf,smb_size);
+ set_message(cli->outbuf,0,4 + strlen(path2),True);
+ SCVAL(cli->outbuf,smb_com,SMBchkpth);
+ SSVAL(cli->outbuf,smb_tid,cli->cnum);
+ cli_setup_packet(cli);
+
+ p = smb_buf(cli->outbuf);
+ *p++ = 4;
+ fstrcpy(p,path2);
+
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
+ return False;
+ }
+
+ if (cli_error(cli, NULL, NULL)) return False;
+
+ return True;
+}
+
+
+/****************************************************************************
+start a message sequence
+****************************************************************************/
+BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
+ int *grp)
+{
+ char *p;
+
+ /* send a SMBsendstrt command */
+ bzero(cli->outbuf,smb_size);
+ set_message(cli->outbuf,0,0,True);
+ CVAL(cli->outbuf,smb_com) = SMBsendstrt;
+ SSVAL(cli->outbuf,smb_tid,cli->cnum);
+ cli_setup_packet(cli);
+
+ p = smb_buf(cli->outbuf);
+ *p++ = 4;
+ pstrcpy(p,username);
+ p = skip_string(p,1);
+ *p++ = 4;
+ pstrcpy(p,host);
+ p = skip_string(p,1);
+
+ set_message(cli->outbuf,0,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
+
+ cli_send_smb(cli, True);
+
+ if (!cli_receive_smb(cli)) {
+ return False;
+ }
+
+ if (cli_error(cli, NULL, NULL)) return False;
+
+ *grp = SVAL(cli->inbuf,smb_vwv0);
+
+ return True;
+}
+
+
+/****************************************************************************
+send a message
+****************************************************************************/
+BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
+{
+ char *p;
+
+ bzero(cli->outbuf,smb_size);
+ set_message(cli->outbuf,1,len+3,True);
+ CVAL(cli->outbuf,smb_com) = SMBsendtxt;
+ SSVAL(cli->outbuf,smb_tid,cli->cnum);
+ cli_setup_packet(cli);
+
+ SSVAL(cli->outbuf,smb_vwv0,grp);
+
+ p = smb_buf(cli->outbuf);
+ *p = 1;
+ SSVAL(p,1,len);
+ memcpy(p+3,msg,len);
+ cli_send_smb(cli, True);
+
+ if (!cli_receive_smb(cli)) {
+ return False;
+ }
+
+ if (cli_error(cli, NULL, NULL)) return False;
+
+ return True;
+}
+
+/****************************************************************************
+end a message
+****************************************************************************/
+BOOL cli_message_end(struct cli_state *cli, int grp)
+{
+ bzero(cli->outbuf,smb_size);
+ set_message(cli->outbuf,1,0,True);
+ CVAL(cli->outbuf,smb_com) = SMBsendend;
+ SSVAL(cli->outbuf,smb_tid,cli->cnum);
+
+ SSVAL(cli->outbuf,smb_vwv0,grp);
+
+ cli_setup_packet(cli);
+
+ cli_send_smb(cli, True);
+
+ if (!cli_receive_smb(cli)) {
+ return False;
+ }
+
+ if (cli_error(cli, NULL, NULL)) return False;
+
+ return True;
+}
+
+
+/****************************************************************************
+query disk space
+****************************************************************************/
+BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail)
+{
+ bzero(cli->outbuf,smb_size);
+ set_message(cli->outbuf,0,0,True);
+ CVAL(cli->outbuf,smb_com) = SMBdskattr;
+ SSVAL(cli->outbuf,smb_tid,cli->cnum);
+ cli_setup_packet(cli);
+
+ cli_send_smb(cli, True);
+ if (!cli_receive_smb(cli)) {
+ return False;
+ }
+
+ *bsize = SVAL(cli->inbuf,smb_vwv1)*SVAL(cli->inbuf,smb_vwv2);
+ *total = SVAL(cli->inbuf,smb_vwv0);
+ *avail = SVAL(cli->inbuf,smb_vwv3);
+
+ return True;
+}