-send a tree disconnect
-****************************************************************************/
-BOOL cli_tdis(struct cli_state *cli)
-{
- bzero(cli->outbuf,smb_size);
- set_message(cli->outbuf,0,0,True);
- CVAL(cli->outbuf,smb_com) = SMBtdis;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli))
- return False;
-
- return CVAL(cli->inbuf,smb_rcls) == 0;
-}
-
-/****************************************************************************
-rename a file
-****************************************************************************/
-BOOL cli_rename(struct cli_state *cli, char *fname_src, char *fname_dst)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,1, 4 + strlen(fname_src) + strlen(fname_dst), True);
-
- CVAL(cli->outbuf,smb_com) = SMBmv;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN);
-
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- pstrcpy(p,fname_src);
- p = skip_string(p,1);
- *p++ = 4;
- pstrcpy(p,fname_dst);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-delete a file
-****************************************************************************/
-BOOL cli_unlink(struct cli_state *cli, char *fname)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,1, 2 + strlen(fname),True);
-
- CVAL(cli->outbuf,smb_com) = SMBunlink;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN);
-
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- pstrcpy(p,fname);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-create a directory
-****************************************************************************/
-BOOL cli_mkdir(struct cli_state *cli, char *dname)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,0, 2 + strlen(dname),True);
-
- CVAL(cli->outbuf,smb_com) = SMBmkdir;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- pstrcpy(p,dname);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-remove a directory
-****************************************************************************/
-BOOL cli_rmdir(struct cli_state *cli, char *dname)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,0, 2 + strlen(dname),True);
-
- CVAL(cli->outbuf,smb_com) = SMBrmdir;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- pstrcpy(p,dname);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-
-
-/****************************************************************************
-open a file
-****************************************************************************/
-int cli_nt_create(struct cli_state *cli, char *fname)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,24,1 + strlen(fname),True);
-
- CVAL(cli->outbuf,smb_com) = SMBntcreateX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,0xFF);
- SIVAL(cli->outbuf,smb_ntcreate_Flags, 0x06);
- SIVAL(cli->outbuf,smb_ntcreate_RootDirectoryFid, 0x0);
- SIVAL(cli->outbuf,smb_ntcreate_DesiredAccess, 0x2019f);
- SIVAL(cli->outbuf,smb_ntcreate_FileAttributes, 0x0);
- SIVAL(cli->outbuf,smb_ntcreate_ShareAccess, 0x03);
- SIVAL(cli->outbuf,smb_ntcreate_CreateDisposition, 0x01);
- SIVAL(cli->outbuf,smb_ntcreate_CreateOptions, 0x0);
- SIVAL(cli->outbuf,smb_ntcreate_ImpersonationLevel, 0x02);
- SSVAL(cli->outbuf,smb_ntcreate_NameLength, strlen(fname));
-
- p = smb_buf(cli->outbuf);
- pstrcpy(p,fname);
- p = skip_string(p,1);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return -1;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return -1;
- }
-
- return SVAL(cli->inbuf,smb_vwv2 + 1);
-}
-
-
-/****************************************************************************
-open a file
-****************************************************************************/
-int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
-{
- char *p;
- unsigned openfn=0;
- unsigned accessmode=0;
-
- /* you must open for RW not just write - otherwise getattrE doesn't
- work! */
- if ((flags & O_ACCMODE) == O_WRONLY && strncmp(cli->dev, "LPT", 3)) {
- flags = (flags & ~O_ACCMODE) | O_RDWR;
- }
-
- if (flags & O_CREAT)
- openfn |= (1<<4);
- if (!(flags & O_EXCL)) {
- if (flags & O_TRUNC)
- openfn |= (1<<1);
- else
- openfn |= (1<<0);
- }
-
- accessmode = (share_mode<<4);
-
- if ((flags & O_ACCMODE) == O_RDWR) {
- accessmode |= 2;
- } else if ((flags & O_ACCMODE) == O_WRONLY) {
- accessmode |= 1;
- }
-
-#if defined(O_SYNC)
- if ((flags & O_SYNC) == O_SYNC) {
- accessmode |= (1<<14);
- }
-#endif /* O_SYNC */
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,15,1 + strlen(fname),True);
-
- CVAL(cli->outbuf,smb_com) = SMBopenX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,0xFF);
- SSVAL(cli->outbuf,smb_vwv2,0); /* no additional info */
- SSVAL(cli->outbuf,smb_vwv3,accessmode);
- SSVAL(cli->outbuf,smb_vwv4,aSYSTEM | aHIDDEN);
- SSVAL(cli->outbuf,smb_vwv5,0);
- SSVAL(cli->outbuf,smb_vwv8,openfn);
-
- p = smb_buf(cli->outbuf);
- p = cli_put_string(cli, p, fname, False);
-
- set_message(cli->outbuf,15,PTR_DIFF(p, smb_buf(cli->outbuf)),False);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return -1;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return -1;
- }
-
- return SVAL(cli->inbuf,smb_vwv2);
-}
-
-
-
-
-/****************************************************************************
- close a file
-****************************************************************************/
-BOOL cli_close(struct cli_state *cli, int fnum)
-{
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,3,0,True);
-
- CVAL(cli->outbuf,smb_com) = SMBclose;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,fnum);
- SIVALS(cli->outbuf,smb_vwv1,-1);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-
-/****************************************************************************
- lock a file
-****************************************************************************/
-BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout)
-{
- char *p;
- int saved_timeout = cli->timeout;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,8,10,True);
-
- CVAL(cli->outbuf,smb_com) = SMBlockingX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- CVAL(cli->outbuf,smb_vwv0) = 0xFF;
- SSVAL(cli->outbuf,smb_vwv2,fnum);
- CVAL(cli->outbuf,smb_vwv3) = 0;
- SIVALS(cli->outbuf, smb_vwv4, timeout);
- SSVAL(cli->outbuf,smb_vwv6,0);
- SSVAL(cli->outbuf,smb_vwv7,1);
-
- p = smb_buf(cli->outbuf);
- SSVAL(p, 0, cli->pid);
- SIVAL(p, 2, offset);
- SIVAL(p, 6, len);
- cli_send_smb(cli, True);
-
- cli->timeout = (timeout == -1) ? 0x7FFFFFFF : timeout;
-
- if (!cli_receive_smb(cli)) {
- cli->timeout = saved_timeout;
- return False;
- }
-
- cli->timeout = saved_timeout;
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
- unlock a file
-****************************************************************************/
-BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,8,10,True);
-
- CVAL(cli->outbuf,smb_com) = SMBlockingX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- CVAL(cli->outbuf,smb_vwv0) = 0xFF;
- SSVAL(cli->outbuf,smb_vwv2,fnum);
- CVAL(cli->outbuf,smb_vwv3) = 0;
- SIVALS(cli->outbuf, smb_vwv4, timeout);
- SSVAL(cli->outbuf,smb_vwv6,1);
- SSVAL(cli->outbuf,smb_vwv7,0);
-
- p = smb_buf(cli->outbuf);
- SSVAL(p, 0, cli->pid);
- SIVAL(p, 2, offset);
- SIVAL(p, 6, len);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-
-
-/****************************************************************************
-issue a single SMBread and don't wait for a reply
-****************************************************************************/
-static void cli_issue_read(struct cli_state *cli, int fnum, off_t offset,
- size_t size, int i)
-{
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,10,0,True);
-
- CVAL(cli->outbuf,smb_com) = SMBreadX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- CVAL(cli->outbuf,smb_vwv0) = 0xFF;
- SSVAL(cli->outbuf,smb_vwv2,fnum);
- SIVAL(cli->outbuf,smb_vwv3,offset);
- SSVAL(cli->outbuf,smb_vwv5,size);
- SSVAL(cli->outbuf,smb_vwv6,size);
- SSVAL(cli->outbuf,smb_mid,cli->mid + i);
-
- cli_send_smb(cli, True);
-}
-
-/****************************************************************************
- read from a file
-****************************************************************************/
-size_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size)
-{
- char *p;
- int total = -1;
- int issued=0;
- int received=0;
- int mpx = MAX(cli->max_mux-1, 1);
- int block = (cli->max_xmit - (smb_size+32)) & ~1023;
- int mid;
- int blocks = (size + (block-1)) / block;
-
- if (size == 0) return 0;
-
- while (received < blocks)
- {
- int size2;
-
- while (issued - received < mpx && issued < blocks) {
- int size1 = MIN(block, size-issued*block);
- cli_issue_read(cli, fnum, offset+issued*block, size1, issued);
- issued++;
- }
-
- if (!cli_receive_smb(cli)) {
- return total;
- }
-
- received++;
- mid = SVAL(cli->inbuf, smb_mid) - cli->mid;
- size2 = SVAL(cli->inbuf, smb_vwv5);
-
- if (cli_error(cli, NULL, NULL))
- {
- blocks = MIN(blocks, mid-1);
- continue;
- }
-
- if (size2 <= 0) {
- blocks = MIN(blocks, mid-1);
- /* this distinguishes EOF from an error */
- total = MAX(total, 0);
- continue;
- }
-
- if (size2 > block) {
- DEBUG(0,("server returned more than we wanted!\n"));
- exit(1);
- }
- if (mid >= issued) {
- DEBUG(0,("invalid mid from server!\n"));
- exit(1);
- }
- p = smb_base(cli->inbuf) + SVAL(cli->inbuf,smb_vwv6);
-
- memcpy(buf+mid*block, p, size2);
-
- total = MAX(total, mid*block + size2);
- }
-
- while (received < issued) {
- cli_receive_smb(cli);
- received++;
- }
-
- return total;
-}
-
-
-/****************************************************************************
-issue a single SMBwrite and don't wait for a reply
-****************************************************************************/
-static void cli_issue_write(struct cli_state *cli, int fnum, off_t offset, uint16 mode, char *buf,
- size_t size, int i)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,12,size,True);
-
- CVAL(cli->outbuf,smb_com) = SMBwriteX;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- CVAL(cli->outbuf,smb_vwv0) = 0xFF;
- SSVAL(cli->outbuf,smb_vwv2,fnum);
-
- SIVAL(cli->outbuf,smb_vwv3,offset);
- SIVAL(cli->outbuf,smb_vwv5,IS_BITS_SET_ALL(mode, 0x0008) ? 0xFFFFFFFF : 0);
- SSVAL(cli->outbuf,smb_vwv7,mode);
-
- SSVAL(cli->outbuf,smb_vwv8,IS_BITS_SET_ALL(mode, 0x0008) ? size : 0);
- SSVAL(cli->outbuf,smb_vwv10,size);
- SSVAL(cli->outbuf,smb_vwv11,
- smb_buf(cli->outbuf) - smb_base(cli->outbuf));
-
- p = smb_base(cli->outbuf) + SVAL(cli->outbuf,smb_vwv11);
- memcpy(p, buf, size);
-
- SSVAL(cli->outbuf,smb_mid,cli->mid + i);
-
- cli_send_smb(cli, True);
-}
-
-/****************************************************************************
- write to a file
- write_mode: 0x0001 disallow write cacheing
- 0x0002 return bytes remaining
- 0x0004 use raw named pipe protocol
- 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 total = -1;
- int issued=0;
- int received=0;
- int mpx = MAX(cli->max_mux-1, 1);
- int block = (cli->max_xmit - (smb_size+32)) & ~1023;
- int mid;
- int blocks = (size + (block-1)) / block;
-
- if (size == 0) return 0;
-
- while (received < blocks) {
- int size2;
-
- while (issued - received < mpx && issued < blocks) {
- int size1 = MIN(block, size-issued*block);
- cli_issue_write(cli, fnum, offset+issued*block,
- write_mode,
- buf + issued*block,
- size1, issued);
- issued++;
- }
-
- if (!cli_receive_smb(cli)) {
- return total;
- }
-
- received++;
- mid = SVAL(cli->inbuf, smb_mid) - cli->mid;
- size2 = SVAL(cli->inbuf, smb_vwv2);
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- blocks = MIN(blocks, mid-1);
- continue;
- }
-
- if (size2 <= 0) {
- blocks = MIN(blocks, mid-1);
- /* this distinguishes EOF from an error */
- total = MAX(total, 0);
- continue;
- }
-
- total += size2;
-
- total = MAX(total, mid*block + size2);
- }
-
- while (received < issued) {
- cli_receive_smb(cli);
- received++;
- }
-
- return total;
-}
-
-
-/****************************************************************************
-do a SMBgetattrE call
-****************************************************************************/
-BOOL cli_getattrE(struct cli_state *cli, int fd,
- uint16 *attr, size_t *size,
- time_t *c_time, time_t *a_time, time_t *m_time)
-{
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,2,0,True);
-
- CVAL(cli->outbuf,smb_com) = SMBgetattrE;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,fd);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- if (size) {
- *size = IVAL(cli->inbuf, smb_vwv6);
- }
-
- if (attr) {
- *attr = SVAL(cli->inbuf,smb_vwv10);
- }
-
- if (c_time) {
- *c_time = make_unix_date3(cli->inbuf+smb_vwv0);
- }
-
- if (a_time) {
- *a_time = make_unix_date3(cli->inbuf+smb_vwv2);
- }
-
- if (m_time) {
- *m_time = make_unix_date3(cli->inbuf+smb_vwv4);
- }
-
- return True;
-}
-
-
-/****************************************************************************
-do a SMBgetatr call
-****************************************************************************/
-BOOL cli_getatr(struct cli_state *cli, char *fname,
- uint16 *attr, size_t *size, time_t *t)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,0,strlen(fname)+2,True);
-
- CVAL(cli->outbuf,smb_com) = SMBgetatr;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- p = smb_buf(cli->outbuf);
- *p = 4;
- pstrcpy(p+1, fname);
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- if (size) {
- *size = IVAL(cli->inbuf, smb_vwv3);
- }
-
- if (t) {
- *t = make_unix_date3(cli->inbuf+smb_vwv1);
- }
-
- if (attr) {
- *attr = SVAL(cli->inbuf,smb_vwv0);
- }
-
-
- return True;
-}
-
-
-/****************************************************************************
-do a SMBsetatr call
-****************************************************************************/
-BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t)
-{
- char *p;
-
- bzero(cli->outbuf,smb_size);
- bzero(cli->inbuf,smb_size);
-
- set_message(cli->outbuf,8,strlen(fname)+4,True);
-
- CVAL(cli->outbuf,smb_com) = SMBsetatr;
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0, attr);
- put_dos_date3(cli->outbuf,smb_vwv1, t);
-
- p = smb_buf(cli->outbuf);
- *p = 4;
- pstrcpy(p+1, fname);
- p = skip_string(p,1);
- *p = 4;
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0) {
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-send a qpathinfo call
-****************************************************************************/
-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, uint16 *mode)
-{
- int data_len = 0;
- int param_len = 0;
- uint16 setup = TRANSACT2_QPATHINFO;
- pstring param;
- char *rparam=NULL, *rdata=NULL;
- int count=8;
- BOOL ret;
- time_t (*date_fn)(void *);
-
- param_len = strlen(fname) + 7;
-
- memset(param, 0, param_len);
- SSVAL(param, 0, SMB_INFO_STANDARD);
- pstrcpy(¶m[6], fname);
-
- do {
- ret = (cli_send_trans(cli, SMBtrans2,
- NULL, 0, /* Name, length */
- -1, 0, /* fid, flags */
- &setup, 1, 0, /* setup, length, max */
- param, param_len, 10, /* param, length, max */
- NULL, data_len, cli->max_xmit /* data, length, max */
- ) &&
- cli_receive_trans(cli, SMBtrans2,
- &rparam, ¶m_len,
- &rdata, &data_len));
- if (!ret) {
- /* we need to work around a Win95 bug - sometimes
- it gives ERRSRV/ERRerror temprarily */
- uint8 eclass;
- uint32 ecode;
- cli_error(cli, &eclass, &ecode);
- if (eclass != ERRSRV || ecode != ERRerror) break;
- msleep(100);
- }
- } while (count-- && ret==False);
-
- if (!ret || !rdata || data_len < 22) {
- return False;
- }
-
- if (cli->win95) {
- date_fn = make_unix_date;
- } else {
- date_fn = make_unix_date2;
- }
-
- if (c_time) {
- *c_time = date_fn(rdata+0);
- }
- if (a_time) {
- *a_time = date_fn(rdata+4);
- }
- if (m_time) {
- *m_time = date_fn(rdata+8);
- }
- if (size) {
- *size = IVAL(rdata, 12);
- }
- if (mode) {
- *mode = SVAL(rdata,l1_attrFile);
- }
-
- if (rdata) free(rdata);
- if (rparam) free(rparam);
- return True;
-}
-
-/****************************************************************************
-send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
-****************************************************************************/
-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, uint16 *mode,
- SMB_INO_T *ino)
-{
- int data_len = 0;
- int param_len = 0;
- uint16 setup = TRANSACT2_QPATHINFO;
- pstring param;
- char *rparam=NULL, *rdata=NULL;
-
- param_len = strlen(fname) + 7;
-
- memset(param, 0, param_len);
- SSVAL(param, 0, SMB_QUERY_FILE_ALL_INFO);
- pstrcpy(¶m[6], fname);
-
- if (!cli_send_trans(cli, SMBtrans2,
- NULL, 0, /* name, length */
- -1, 0, /* fid, flags */
- &setup, 1, 0, /* setup, length, max */
- param, param_len, 10, /* param, length, max */
- NULL, data_len, cli->max_xmit /* data, length, max */
- )) {
- return False;
- }
-
- if (!cli_receive_trans(cli, SMBtrans2,
- &rparam, ¶m_len,
- &rdata, &data_len)) {
- return False;
- }
-
- if (!rdata || data_len < 22) {
- return False;
- }
-
- if (c_time) {
- *c_time = interpret_long_date(rdata+0) - cli->serverzone;
- }
- if (a_time) {
- *a_time = interpret_long_date(rdata+8) - cli->serverzone;
- }
- if (m_time) {
- *m_time = interpret_long_date(rdata+16) - cli->serverzone;
- }
- 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 (ino) {
- *ino = IVAL(rdata, 64);
- }
-
- if (rdata) free(rdata);
- if (rparam) free(rparam);
- return True;
-}
-
-
-/****************************************************************************
-send a qfileinfo call
-****************************************************************************/
-BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
- 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;
- uint16 setup = TRANSACT2_QFILEINFO;
- 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_QUERY_FILE_ALL_INFO);
-
- if (!cli_send_trans(cli, SMBtrans2,
- NULL, 0, /* name, length */
- -1, 0, /* fid, flags */
- &setup, 1, 0, /* setup, length, max */
- param, param_len, 2, /* param, length, max */
- NULL, data_len, cli->max_xmit /* data, length, max */
- )) {
- return False;
- }
-
- if (!cli_receive_trans(cli, SMBtrans2,
- &rparam, ¶m_len,
- &rdata, &data_len)) {
- return False;
- }
-
- if (!rdata || data_len < 68) {
- return False;
- }
-
- if (c_time) {
- *c_time = interpret_long_date(rdata+0) - cli->serverzone;
- }
- if (a_time) {
- *a_time = interpret_long_date(rdata+8) - cli->serverzone;
- }
- if (m_time) {
- *m_time = interpret_long_date(rdata+16) - cli->serverzone;
- }
- 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 (ino) {
- *ino = IVAL(rdata, 64);
- }
-
- if (rdata) free(rdata);
- if (rparam) free(rparam);
- return True;
-}
-
-
-/****************************************************************************
-interpret a long filename structure - this is mostly guesses at the moment
-The length of the structure is returned
-The structure of a long filename depends on the info level. 260 is used
-by NT and 2 is used by OS/2
-****************************************************************************/
-static int interpret_long_filename(int level,char *p,file_info *finfo)
-{
- extern file_info def_finfo;
-
- if (finfo)
- memcpy(finfo,&def_finfo,sizeof(*finfo));
-
- switch (level)
- {
- case 1: /* OS/2 understands this */
- if (finfo) {
- /* these dates are converted to GMT by make_unix_date */
- finfo->ctime = make_unix_date2(p+4);
- finfo->atime = make_unix_date2(p+8);
- finfo->mtime = make_unix_date2(p+12);
- finfo->size = IVAL(p,16);
- finfo->mode = CVAL(p,24);
- pstrcpy(finfo->name,p+27);
- }
- return(28 + CVAL(p,26));
-
- case 2: /* this is what OS/2 uses mostly */
- if (finfo) {
- /* these dates are converted to GMT by make_unix_date */
- finfo->ctime = make_unix_date2(p+4);
- finfo->atime = make_unix_date2(p+8);
- finfo->mtime = make_unix_date2(p+12);
- finfo->size = IVAL(p,16);
- finfo->mode = CVAL(p,24);
- pstrcpy(finfo->name,p+31);
- }
- return(32 + CVAL(p,30));
-
- /* levels 3 and 4 are untested */
- case 3:
- if (finfo) {
- /* these dates are probably like the other ones */
- finfo->ctime = make_unix_date2(p+8);
- finfo->atime = make_unix_date2(p+12);
- finfo->mtime = make_unix_date2(p+16);
- finfo->size = IVAL(p,20);
- finfo->mode = CVAL(p,28);
- pstrcpy(finfo->name,p+33);
- }
- return(SVAL(p,4)+4);
-
- case 4:
- if (finfo) {
- /* these dates are probably like the other ones */
- finfo->ctime = make_unix_date2(p+8);
- finfo->atime = make_unix_date2(p+12);
- finfo->mtime = make_unix_date2(p+16);
- finfo->size = IVAL(p,20);
- finfo->mode = CVAL(p,28);
- pstrcpy(finfo->name,p+37);
- }
- return(SVAL(p,4)+4);
-
- case 260: /* NT uses this, but also accepts 2 */
- if (finfo) {
- int ret = SVAL(p,0);
- int namelen;
- p += 4; /* next entry offset */
- p += 4; /* fileindex */
-
- /* these dates appear to arrive in a
- weird way. It seems to be localtime
- plus the serverzone given in the
- initial connect. This is GMT when
- DST is not in effect and one hour
- from GMT otherwise. Can this really
- be right??
-
- I suppose this could be called
- kludge-GMT. Is is the GMT you get
- by using the current DST setting on
- a different localtime. It will be
- cheap to calculate, I suppose, as
- no DST tables will be needed */
-
- finfo->ctime = interpret_long_date(p); p += 8;
- finfo->atime = interpret_long_date(p); p += 8;
- finfo->mtime = interpret_long_date(p); p += 8; p += 8;
- finfo->size = IVAL(p,0); p += 8;
- p += 8; /* alloc size */
- finfo->mode = CVAL(p,0); p += 4;
- namelen = IVAL(p,0); p += 4;
- p += 4; /* EA size */
- p += 2; /* short name len? */
- p += 24; /* short name? */
- StrnCpy(finfo->name,p,namelen);
- return(ret);
- }
- return(SVAL(p,0));
- }
-
- DEBUG(1,("Unknown long filename format %d\n",level));
- return(SVAL(p,0));
-}
-
-
-/****************************************************************************
- do a directory listing, calling fn on each file found
- ****************************************************************************/
-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. */
- int info_level = cli->protocol<PROTOCOL_NT1?1:260;
- char *p, *p2;
- pstring mask;
- file_info finfo;
- int i;
- char *dirlist = NULL;
- int dirlist_len = 0;
- int total_received = -1;
- BOOL First = True;
- int ff_resume_key = 0;
- int ff_searchcount=0;
- int ff_eos=0;
- int ff_lastname=0;
- int ff_dir_handle=0;
- int loop_count = 0;
- char *rparam=NULL, *rdata=NULL;
- int param_len, data_len;
-
- uint16 setup;
- pstring param;
-
- pstrcpy(mask,Mask);
-
- while (ff_eos == 0) {
- loop_count++;
- if (loop_count > 200) {
- DEBUG(0,("Error: Looping in FIND_NEXT??\n"));
- break;
- }
-
- param_len = 12+strlen(mask)+1;
-
- if (First) {
- setup = TRANSACT2_FINDFIRST;
- SSVAL(param,0,attribute); /* attribute */
- SSVAL(param,2,max_matches); /* max count */
- SSVAL(param,4,8+4+2); /* resume required + close on end + continue */
- SSVAL(param,6,info_level);
- SIVAL(param,8,0);
- pstrcpy(param+12,mask);
- } else {
- setup = TRANSACT2_FINDNEXT;
- SSVAL(param,0,ff_dir_handle);
- SSVAL(param,2,max_matches); /* max count */
- SSVAL(param,4,info_level);
- SIVAL(param,6,ff_resume_key); /* ff_resume_key */
- SSVAL(param,10,8+4+2); /* resume required + close on end + continue */
- pstrcpy(param+12,mask);
-
- DEBUG(5,("hand=0x%X resume=%d ff_lastname=%d mask=%s\n",
- ff_dir_handle,ff_resume_key,ff_lastname,mask));
- }
-
- if (!cli_send_trans(cli, SMBtrans2,
- NULL, 0, /* Name, length */
- -1, 0, /* fid, flags */
- &setup, 1, 0, /* setup, length, max */
- param, param_len, 10, /* param, length, max */
- NULL, 0,
- cli->max_xmit /* data, length, max */
- )) {
- break;
- }
-
- if (!cli_receive_trans(cli, SMBtrans2,
- &rparam, ¶m_len,
- &rdata, &data_len)) {
- /* we need to work around a Win95 bug - sometimes
- it gives ERRSRV/ERRerror temprarily */
- uint8 eclass;
- uint32 ecode;
- cli_error(cli, &eclass, &ecode);
- if (eclass != ERRSRV || ecode != ERRerror) break;
- msleep(100);
- continue;
- }
-
- if (total_received == -1) total_received = 0;
-
- /* parse out some important return info */
- p = rparam;
- if (First) {
- ff_dir_handle = SVAL(p,0);
- ff_searchcount = SVAL(p,2);
- ff_eos = SVAL(p,4);
- ff_lastname = SVAL(p,8);
- } else {
- ff_searchcount = SVAL(p,0);
- ff_eos = SVAL(p,2);
- ff_lastname = SVAL(p,6);
- }
-
- if (ff_searchcount == 0)
- break;
-
- /* point to the data bytes */
- p = rdata;
-
- /* we might need the lastname for continuations */
- if (ff_lastname > 0) {
- switch(info_level)
- {
- case 260:
- ff_resume_key =0;
- StrnCpy(mask,p+ff_lastname,
- data_len-ff_lastname);
- break;
- case 1:
- pstrcpy(mask,p + ff_lastname + 1);
- ff_resume_key = 0;
- break;
- }
- } else {
- pstrcpy(mask,"");
- }
-
- /* and add them to the dirlist pool */
- dirlist = Realloc(dirlist,dirlist_len + data_len);
-
- if (!dirlist) {
- DEBUG(0,("Failed to expand dirlist\n"));
- break;
- }
-
- /* put in a length for the last entry, to ensure we can chain entries
- into the next packet */
- for (p2=p,i=0;i<(ff_searchcount-1);i++)
- p2 += interpret_long_filename(info_level,p2,NULL);
- SSVAL(p2,0,data_len - PTR_DIFF(p2,p));
-
- /* grab the data for later use */
- memcpy(dirlist+dirlist_len,p,data_len);
- dirlist_len += data_len;
-
- total_received += ff_searchcount;
-
- if (rdata) free(rdata); rdata = NULL;
- if (rparam) free(rparam); rparam = NULL;
-
- DEBUG(3,("received %d entries (eos=%d resume=%d)\n",
- ff_searchcount,ff_eos,ff_resume_key));
-
- First = False;
- }
-
- for (p=dirlist,i=0;i<total_received;i++) {
- p += interpret_long_filename(info_level,p,&finfo);
- fn(&finfo, Mask);
- }
-
- /* free up the dirlist buffer */
- if (dirlist) free(dirlist);
- return(total_received);
-}
-
-
-/****************************************************************************
-Send a SamOEMChangePassword command
-****************************************************************************/
-
-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];
- char *p = param;
- fstring upper_case_old_pw;
- fstring upper_case_new_pw;
- unsigned char old_pw_hash[16];
- unsigned char new_pw_hash[16];
- int data_len;
- int param_len = 0;
- char *rparam = NULL;
- char *rdata = NULL;
- int rprcnt, rdrcnt;
-
- if (strlen(user) >= sizeof(fstring)-1) {
- DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
- return False;
- }
-
- SSVAL(p,0,214); /* SamOEMChangePassword command. */
- p += 2;
- pstrcpy(p, "zsT");
- p = skip_string(p,1);
- pstrcpy(p, "B516B16");
- p = skip_string(p,1);
- pstrcpy(p,user);
- p = skip_string(p,1);
- SSVAL(p,0,532);
- p += 2;
-
- param_len = PTR_DIFF(p,param);
-
- /*
- * Get the Lanman hash of the old password, we
- * use this as the key to make_oem_passwd_hash().
- */
- memset(upper_case_old_pw, '\0', sizeof(upper_case_old_pw));
- fstrcpy(upper_case_old_pw, old_password);
- strupper(upper_case_old_pw);
- E_P16((uchar *)upper_case_old_pw, old_pw_hash);
-
- if (!make_oem_passwd_hash( data, new_password, old_pw_hash, False))
- {
- return False;
- }
-
- /*
- * Now place the old password hash in the data.
- */
- memset(upper_case_new_pw, '\0', sizeof(upper_case_new_pw));
- fstrcpy(upper_case_new_pw, new_password);
- strupper(upper_case_new_pw);
-
- E_P16((uchar *)upper_case_new_pw, new_pw_hash);
-
- E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
-
- data_len = 532;
-
- 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 */
- ))
- {
- DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
- user ));
- return False;
- }
-
- if (cli_receive_trans(cli,SMBtrans,
- &rparam, &rprcnt,
- &rdata, &rdrcnt)) {
- if (rparam)
- cli->rap_error = SVAL(rparam,0);
- }
-
- if (rparam)
- free(rparam);
- if (rdata)
- free(rdata);
-
- return (cli->rap_error == 0);
-}
-
-/****************************************************************************
-send a negprot command
-****************************************************************************/
-BOOL cli_negprot(struct cli_state *cli)
-{
- char *p;
- int numprots;
- int plength;
-
- bzero(cli->outbuf,smb_size);
-
- /* setup the protocol strings */
- for (plength=0,numprots=0;
- prots[numprots].name && prots[numprots].prot<=cli->protocol;
- numprots++)
- plength += strlen(prots[numprots].name)+2;
-
- set_message(cli->outbuf,0,plength,True);
-
- p = smb_buf(cli->outbuf);
- for (numprots=0;
- prots[numprots].name && prots[numprots].prot<=cli->protocol;
- numprots++) {
- *p++ = 2;
- pstrcpy(p,prots[numprots].name);
- p += strlen(p) + 1;
- }
-
- CVAL(cli->outbuf,smb_com) = SMBnegprot;
- cli_setup_packet(cli);
-
- CVAL(smb_buf(cli->outbuf),0) = 2;
-
- cli_send_smb(cli, True);
- if (!cli_receive_smb(cli))
- {
- return False;
- }
-
- if (CVAL(cli->inbuf,smb_rcls) != 0 ||
- ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {
- return(False);
- }
-
- cli->protocol = prots[SVAL(cli->inbuf,smb_vwv0)].prot;
-
-
- if (cli->protocol >= PROTOCOL_NT1)
- {
- char *buf = smb_buf(cli->inbuf);
- int bcc = SVAL(cli->inbuf,smb_vwv+2*(CVAL(cli->inbuf,smb_wct)));
- /* NT protocol */
- cli->sec_mode = CVAL(cli->inbuf,smb_vwv1);
- cli->max_mux = SVAL(cli->inbuf, smb_vwv1+1);
- cli->max_xmit = IVAL(cli->inbuf,smb_vwv3+1);
- cli->sesskey = IVAL(cli->inbuf,smb_vwv7+1);
- cli->serverzone = SVALS(cli->inbuf,smb_vwv15+1)*60;
- /* this time arrives in real GMT */
- cli->servertime = interpret_long_date(cli->inbuf+smb_vwv11+1);
-
- cli->capabilities = IVAL(cli->inbuf,smb_vwv9+1);
- if (IS_BITS_SET_ALL(cli->capabilities, CAP_RAW_MODE))
- {
- cli->readbraw_supported = True;
- cli->writebraw_supported = True;
- }
-
- if (IS_BITS_SET_ALL(cli->capabilities, CAP_EXTENDED_SECURITY))
- {
- /* oops, some kerberos-related nonsense. */
- /* expect to have to use NTLMSSP-over-SMB */
- DEBUG(10,("unknown kerberos-related (?) blob\n"));
- memset(cli->cryptkey, 0, 8);
- cli->server_domain[0] = 0;
- }
- else
- {
- memcpy(cli->cryptkey, buf,8);
- if (bcc > 8)
- {
- unibuf_to_ascii(cli->server_domain, buf+8,
- sizeof(cli->server_domain));
- }
- else
- {
- cli->server_domain[0] = 0;
- }
- DEBUG(5,("server's domain: %s bcc: %d\n",
- cli->server_domain, bcc));
- }
- }
- else if (cli->protocol >= PROTOCOL_LANMAN1)
- {
- cli->sec_mode = SVAL(cli->inbuf,smb_vwv1);
- cli->max_xmit = SVAL(cli->inbuf,smb_vwv2);
- cli->sesskey = IVAL(cli->inbuf,smb_vwv6);
- cli->serverzone = SVALS(cli->inbuf,smb_vwv10)*60;
- /* this time is converted to GMT by make_unix_date */
- cli->servertime = make_unix_date(cli->inbuf+smb_vwv8);
- cli->readbraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x1) != 0);
- cli->writebraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x2) != 0);
- memcpy(cli->cryptkey,smb_buf(cli->inbuf),8);
- } else {
- /* the old core protocol */
- cli->sec_mode = 0;
- cli->serverzone = TimeDiff(time(NULL));
- }
-
- cli->max_xmit = MIN(cli->max_xmit, CLI_BUFFER_SIZE);
-
- return True;
-}
-
-
-/****************************************************************************
- send a session request. see rfc1002.txt 4.3 and 4.3.2
-****************************************************************************/
-BOOL cli_session_request(struct cli_state *cli,
- struct nmb_name *calling, struct nmb_name *called)
-{
- char *p;
- int len = 4;
- /* send a session request (RFC 1002) */
-
- memcpy(&(cli->calling), calling, sizeof(*calling));
- memcpy(&(cli->called ), called , sizeof(*called ));
-
- if (cli->port == 445)
- {
- return True;
- }
-
- /* put in the destination name */
- p = cli->outbuf+len;
- name_mangle(cli->called .name, p, cli->called .name_type);
- len += name_len(p);
-
- /* and my name */
- p = cli->outbuf+len;
- name_mangle(cli->calling.name, p, cli->calling.name_type);
- len += name_len(p);
-
- /* setup the packet length */
- _smb_setlen(cli->outbuf,len);
- CVAL(cli->outbuf,0) = 0x81;
-
-#ifdef WITH_SSL
-retry:
-#endif /* WITH_SSL */
-
- cli_send_smb(cli, True);
- DEBUG(5,("Sent session request\n"));
-
- if (!cli_receive_smb(cli))
- return False;
-
-#ifdef WITH_SSL
- if (CVAL(cli->inbuf,0) == 0x83 && CVAL(cli->inbuf,4) == 0x8e){ /* use ssl */
- if (!sslutil_fd_is_ssl(cli->fd)){
- if (sslutil_connect(cli->fd) == 0)
- goto retry;
- }
- }
-#endif /* WITH_SSL */
-
- if (CVAL(cli->inbuf,0) != 0x82) {
- /* This is the wrong place to put the error... JRA. */
- cli->rap_error = CVAL(cli->inbuf,0);
- return False;
- }
- return(True);
-}
-
-
-/****************************************************************************
-open the client sockets
-****************************************************************************/
-BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
-{
- extern struct in_addr ipzero;
- int port = cli->port;
-
- fstrcpy(cli->desthost, host);
-
- if (!ip || ip_equal(*ip, ipzero)) {
- if (!resolve_name( cli->desthost, &cli->dest_ip, 0x20)) {
- return False;
- }
- if (ip) *ip = cli->dest_ip;
- } else {
- cli->dest_ip = *ip;
- }
-
-
- if (port == 0) port = SMB_PORT2;
-
- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
- port, cli->timeout);
- if (cli->fd == -1)
- {
- if (cli->port != 0)
- {
- return False;
- }
- port = SMB_PORT;
-
- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
- port, cli->timeout);
- if (cli->fd == -1) return False;
- }
-
- cli->port = port;
-
- return True;
-}
-
-
-/****************************************************************************
-initialise a client structure
-****************************************************************************/
-struct cli_state *cli_initialise(struct cli_state *cli)
-{
- if (!cli) {
- cli = (struct cli_state *)malloc(sizeof(*cli));
- if (!cli)
- return NULL;
- ZERO_STRUCTP(cli);
- }
-
- if (cli->initialised) {
- cli_shutdown(cli);
- }
-
- ZERO_STRUCTP(cli);
-
- cli->port = 0;
- cli->fd = -1;
- cli->cnum = -1;
- cli->pid = (uint16)getpid();
- cli->mid = 1;
- cli->vuid = UID_FIELD_INVALID;
- cli->protocol = PROTOCOL_NT1;
- cli->timeout = 20000;
- cli->bufsize = CLI_BUFFER_SIZE+4;
- cli->max_xmit = cli->bufsize;
- cli->outbuf = (char *)malloc(cli->bufsize);
- cli->inbuf = (char *)malloc(cli->bufsize);
- if (!cli->outbuf || !cli->inbuf)
- {
- return False;
- }
-
- cli->initialised = 1;
- cli->capabilities = CAP_DFS;
-
- return cli;
-}
-
-/****************************************************************************
-close the socket descriptor
-****************************************************************************/
-void cli_close_socket(struct cli_state *cli)
-{
-#ifdef WITH_SSL
- if (cli->fd != -1)
- {
- sslutil_disconnect(cli->fd);
- }
-#endif /* WITH_SSL */
- if (cli->fd != -1)
- {
- close(cli->fd);
- }
- cli->fd = -1;
-}
-
-/****************************************************************************
-shutdown a client structure
-****************************************************************************/
-void cli_shutdown(struct cli_state *cli)
-{
- DEBUG(10,("cli_shutdown\n"));
- if (cli->outbuf)
- {
- free(cli->outbuf);
- }
- if (cli->inbuf)
- {
- free(cli->inbuf);
- }
- cli_close_socket(cli);
- memset(cli, 0, sizeof(*cli));
-}
-
-
-/****************************************************************************
- return error codes for the last packet
- returns 0 if there was no error and the best approx of a unix errno
- otherwise
-
- for 32 bit "warnings", a return code of 0 is expected.
-
-****************************************************************************/
-int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num)
-{
- 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;
-
- if (flgs2 & FLAGS2_32_BIT_ERROR_CODES)
- {
- /* 32 bit error codes detected */
- uint32 nt_err = IVAL(cli->inbuf,smb_rcls);
- if (num) *num = nt_err;
- DEBUG(10,("cli_error: 32 bit codes: code=%08x\n", nt_err));
- if (!IS_BITS_SET_ALL(nt_err, 0xc0000000)) return 0;
-
- switch (nt_err & 0xFFFFFF)
- {
- case NT_STATUS_ACCESS_VIOLATION : return EACCES;
- case NT_STATUS_NO_SUCH_FILE : return ENOENT;
- case NT_STATUS_NO_SUCH_DEVICE : return ENODEV;
- case NT_STATUS_INVALID_HANDLE : return EBADF;
- case NT_STATUS_NO_MEMORY : return ENOMEM;
- case NT_STATUS_ACCESS_DENIED : return EACCES;
- case NT_STATUS_OBJECT_NAME_NOT_FOUND: return ENOENT;
- case NT_STATUS_SHARING_VIOLATION : return EBUSY;
- case NT_STATUS_OBJECT_PATH_INVALID : return ENOTDIR;
- case NT_STATUS_OBJECT_NAME_COLLISION: return EEXIST;
- }
-
- /* for all other cases - a default code */
- return EINVAL;
- }
-
- rcls = CVAL(cli->inbuf,smb_rcls);
- code = SVAL(cli->inbuf,smb_err);
- if (rcls == 0) return 0;
-
- if (eclass) *eclass = rcls;
- if (num ) *num = code;
-
- if (rcls == ERRDOS) {
- switch (code) {
- case ERRbadfile: return ENOENT;
- case ERRbadpath: return ENOTDIR;
- case ERRnoaccess: return EACCES;
- case ERRfilexists: return EEXIST;
- case ERRrename: return EEXIST;
- case ERRbadshare: return EBUSY;
- case ERRlock: return EBUSY;
- case ERRmoredata: return 0; /* Informational only */
- }
- }
- 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 */
- return EINVAL;
-}
-
-/****************************************************************************
-set socket options on a open connection
-****************************************************************************/
-void cli_sockopt(struct cli_state *cli, char *options)
-{
- set_socket_options(cli->fd, options);
-}
-
-/****************************************************************************
-set the PID to use for smb messages. Return the old pid.