smb.h revision 56893
178381Snyan/* 278381Snyan Copyright (C) Andrew Tridgell 1995-1999 378381Snyan 478381Snyan This software may be distributed either under the terms of the 578381Snyan BSD-style license that accompanies tcpdump or the GNU GPL version 2 678381Snyan or later */ 778381Snyan 878381Snyan#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) 978381Snyan#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) 1078381Snyan#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) 1178381Snyan 1278381Snyan#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) 1378381Snyan#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) 1478381Snyan#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) 1578381Snyan#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) 1678381Snyan#define SVALS(buf,pos) ((int16)SVAL(buf,pos)) 1778381Snyan#define IVALS(buf,pos) ((int32)IVAL(buf,pos)) 1878381Snyan#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val))) 19270310Sse#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val))) 2078381Snyan#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val))) 2178381Snyan#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) 2278381Snyan 2378381Snyan/* now the reverse routines - these are used in nmb packets (mostly) */ 2478381Snyan#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) 2578381Snyan#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16))) 2678381Snyan 2778381Snyan#define RSVAL(buf,pos) SREV(SVAL(buf,pos)) 2878381Snyan#define RIVAL(buf,pos) IREV(IVAL(buf,pos)) 2978381Snyan#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val)) 3078381Snyan#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val)) 3178381Snyan 3278381Snyan#define uint16 unsigned short 3378381Snyan#define uint32 unsigned int 3478381Snyan#ifndef uchar 3578381Snyan#define uchar unsigned char 3678381Snyan#endif 3778381Snyan 3878381Snyan#ifndef MIN 3978381Snyan#define MIN(a,b) ((a)<(b)?(a):(b)) 4078381Snyan#endif 4178381Snyan 4278381Snyan/* the complete */ 4378381Snyan#define SMBmkdir 0x00 /* create directory */ 4478381Snyan#define SMBrmdir 0x01 /* delete directory */ 4578381Snyan#define SMBopen 0x02 /* open file */ 4678381Snyan#define SMBcreate 0x03 /* create file */ 4778381Snyan#define SMBclose 0x04 /* close file */ 4878381Snyan#define SMBflush 0x05 /* flush file */ 4978381Snyan#define SMBunlink 0x06 /* delete file */ 5078381Snyan#define SMBmv 0x07 /* rename file */ 5178381Snyan#define SMBgetatr 0x08 /* get file attributes */ 5278381Snyan#define SMBsetatr 0x09 /* set file attributes */ 5378381Snyan#define SMBread 0x0A /* read from file */ 5478381Snyan#define SMBwrite 0x0B /* write to file */ 5578381Snyan#define SMBlock 0x0C /* lock byte range */ 5678381Snyan#define SMBunlock 0x0D /* unlock byte range */ 5778381Snyan#define SMBctemp 0x0E /* create temporary file */ 5878381Snyan#define SMBmknew 0x0F /* make new file */ 5978381Snyan#define SMBchkpth 0x10 /* check directory path */ 6078381Snyan#define SMBexit 0x11 /* process exit */ 6178381Snyan#define SMBlseek 0x12 /* seek */ 6278381Snyan#define SMBtcon 0x70 /* tree connect */ 6378381Snyan#define SMBtconX 0x75 /* tree connect and X*/ 6478381Snyan#define SMBtdis 0x71 /* tree disconnect */ 6578381Snyan#define SMBnegprot 0x72 /* negotiate protocol */ 6678381Snyan#define SMBdskattr 0x80 /* get disk attributes */ 6778381Snyan#define SMBsearch 0x81 /* search directory */ 6878381Snyan#define SMBsplopen 0xC0 /* open print spool file */ 6978381Snyan#define SMBsplwr 0xC1 /* write to print spool file */ 7078381Snyan#define SMBsplclose 0xC2 /* close print spool file */ 7178381Snyan#define SMBsplretq 0xC3 /* return print queue */ 7278381Snyan#define SMBsends 0xD0 /* send single block message */ 7378381Snyan#define SMBsendb 0xD1 /* send broadcast message */ 7478381Snyan#define SMBfwdname 0xD2 /* forward user name */ 7578381Snyan#define SMBcancelf 0xD3 /* cancel forward */ 7678381Snyan#define SMBgetmac 0xD4 /* get machine name */ 7778381Snyan#define SMBsendstrt 0xD5 /* send start of multi-block message */ 7878381Snyan#define SMBsendend 0xD6 /* send end of multi-block message */ 7978381Snyan#define SMBsendtxt 0xD7 /* send text of multi-block message */ 8078381Snyan 8178381Snyan/* Core+ protocol */ 8278381Snyan#define SMBlockread 0x13 /* Lock a range and read */ 8378381Snyan#define SMBwriteunlock 0x14 /* Unlock a range then write */ 8478381Snyan#define SMBreadbraw 0x1a /* read a block of data with no smb header */ 8578381Snyan#define SMBwritebraw 0x1d /* write a block of data with no smb header */ 8678381Snyan#define SMBwritec 0x20 /* secondary write request */ 8778381Snyan#define SMBwriteclose 0x2c /* write a file then close it */ 8878381Snyan 8978381Snyan/* dos extended protocol */ 9078381Snyan#define SMBreadBraw 0x1A /* read block raw */ 9178381Snyan#define SMBreadBmpx 0x1B /* read block multiplexed */ 9278381Snyan#define SMBreadBs 0x1C /* read block (secondary response) */ 9378381Snyan#define SMBwriteBraw 0x1D /* write block raw */ 9478381Snyan#define SMBwriteBmpx 0x1E /* write block multiplexed */ 9578381Snyan#define SMBwriteBs 0x1F /* write block (secondary request) */ 9678381Snyan#define SMBwriteC 0x20 /* write complete response */ 9778381Snyan#define SMBsetattrE 0x22 /* set file attributes expanded */ 9878381Snyan#define SMBgetattrE 0x23 /* get file attributes expanded */ 9978381Snyan#define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ 10078381Snyan#define SMBtrans 0x25 /* transaction - name, bytes in/out */ 10178381Snyan#define SMBtranss 0x26 /* transaction (secondary request/response) */ 10278381Snyan#define SMBioctl 0x27 /* IOCTL */ 10378381Snyan#define SMBioctls 0x28 /* IOCTL (secondary request/response) */ 10478381Snyan#define SMBcopy 0x29 /* copy */ 10578381Snyan#define SMBmove 0x2A /* move */ 10678381Snyan#define SMBecho 0x2B /* echo */ 10778381Snyan#define SMBopenX 0x2D /* open and X */ 10878381Snyan#define SMBreadX 0x2E /* read and X */ 10978381Snyan#define SMBwriteX 0x2F /* write and X */ 11078381Snyan#define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ 11178381Snyan#define SMBffirst 0x82 /* find first */ 11278381Snyan#define SMBfunique 0x83 /* find unique */ 11378381Snyan#define SMBfclose 0x84 /* find close */ 11478381Snyan#define SMBinvalid 0xFE /* invalid command */ 11578381Snyan 11678381Snyan/* Extended 2.0 protocol */ 11778381Snyan#define SMBtrans2 0x32 /* TRANS2 protocol set */ 11878381Snyan#define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */ 11978381Snyan#define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */ 12078381Snyan#define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */ 12178381Snyan#define SMBulogoffX 0x74 /* user logoff */ 12278381Snyan 12378381Snyan/* NT SMB extensions. */ 12478381Snyan#define SMBnttrans 0xA0 /* NT transact */ 12578381Snyan#define SMBnttranss 0xA1 /* NT transact secondary */ 12678381Snyan#define SMBntcreateX 0xA2 /* NT create and X */ 12778381Snyan#define SMBntcancel 0xA4 /* NT cancel */ 12878381Snyan 12978381Snyan/* pathworks special */ 13078381Snyan#define pSETDIR '\377' 13178381Snyan 13278381Snyan 13378381Snyan/* these are the TRANS2 sub commands */ 13478381Snyan#define TRANSACT2_OPEN 0 135#define TRANSACT2_FINDFIRST 1 136#define TRANSACT2_FINDNEXT 2 137#define TRANSACT2_QFSINFO 3 138#define TRANSACT2_SETFSINFO 4 139#define TRANSACT2_QPATHINFO 5 140#define TRANSACT2_SETPATHINFO 6 141#define TRANSACT2_QFILEINFO 7 142#define TRANSACT2_SETFILEINFO 8 143#define TRANSACT2_FSCTL 9 144#define TRANSACT2_IOCTL 10 145#define TRANSACT2_FINDNOTIFYFIRST 11 146#define TRANSACT2_FINDNOTIFYNEXT 12 147#define TRANSACT2_MKDIR 13 148 149#define PTR_DIFF(p1,p2) ((unsigned long)(((char *)(p1)) - (char *)(p2))) 150 151/* some protos */ 152const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf); 153