include/df/smb.hpp

00001 #include <df/smberr.hpp>
00002 
00003 class SMBSession;
00004 
00005 #define SMB_MAX_X 4        //max # of supported andX per packet
00006 #define SMB_MAX_MTU 1456   //1500(EthernetMTU) - 20(IP) - 20(TCP) - 4 (NetBios packet)
00007 
00008 struct SMBCommand {
00009   uint8 cmd;
00010   uint8 errclass;  //DOS
00011   uint16 errcode;  //DOS
00012   uint32 ntstatus; //NT
00013   uint16 tid;  //assigned by server
00014   uint16 uid;  //assigned by server
00015   uint16 pid;  //provided by client
00016   uint16 mid;  //provided by client
00017 //input fields (Core/andX functions) / output fields (Core functions)
00018   uint8 wordcnt;
00019   uint16 *words;
00020   uint16 bytecnt;
00021   uint8 *bytes;
00022 //output fields (andX functions)
00023   uint8 Xcmd;
00024   int Xcnt;  //init zero
00025   uint8 Xwordcnt[SMB_MAX_X];
00026   uint16 *Xwords;
00027   uint16 Xbytecnt[SMB_MAX_X];
00028   uint8 *Xbytes;
00029 };
00030 
00031 class SMBCallback {
00032   public:
00033     virtual void SMBProcessCommand(SMBSession *, SMBCommand *)=0;
00034 };
00035 
00036 class SMBServer : public NetworkServer {
00037   friend class SMBSession;
00038   private:
00039     SMBCallback *callback;
00040     LogFile *lf;
00041   public:
00042     SMBServer();
00043     ~SMBServer();
00044     void SetCallback(SMBCallback *cb);
00045     int16 StartServer(uint16 port);
00046     void SetLogFile(LogFile *lf);
00047 };
00048 
00049 class SMBSession : public NetworkSession {
00050   private:
00051     PTR data, cmd;
00052     uint32 cmdlen, readlen;
00053 #ifdef DEBUG
00054     void LogPacket(PTR, int, BOOL);
00055 #endif
00056     void Log(char *);
00057     ExclusiveThread lock;
00058   public:
00059     SMBSession();
00060     ~SMBSession();
00061     BOOL WriteCommand(SMBCommand *);
00062     BOOL NextX(SMBCommand *);
00063     virtual void Process();
00064     virtual void AsyncRead();   //more data to be read
00065     virtual void AsyncClose();   //more data to be read
00066     BOOL SSLConnect(OpenSSL *);
00067   //user data and helper functions
00068     PTR UserData;  //init NULL
00069     static void Time2timelh(Time &, uint16 &, uint16 &);
00070 };
00071 
00072 #pragma pack(push, 1)
00073 struct smb_header {
00074   //header (32bytes)
00075   uint8 sign[4];  //0xff,'S','M','B'
00076   uint8 cmd;      //see SMB_CMD_...
00077   uint32 ntstatus;//see ntstatus.h
00078   uint8 flgs;     //see SMB_FLG_... (smb_reb)
00079   uint16 flgs2;   //see SMB_SMB_FLG2_...
00080   uint16 pid_hi;  //process id (32bit)
00081   uint64 sign64;  //all zeros
00082   uint16 reserved;//all zeros
00083   uint16 tid;     //tree id : all zeros  (assigned by server)
00084   uint16 pid;     //process id           (given by client)
00085   uint16 uid;     //user id              (assigned by server)
00086   uint16 mid;     //multiplex id         (given by client)
00087   //uint8 wordcnt;
00088   //uint16 data[wordcnt];
00089   //uint16 bytecnt;
00090   //uint8 data[bytecnt];
00091 };
00092 #pragma pack(pop)
00093 
00094 #define SMB_FLG_RESPONSE 0x80  //else REQUEST
00095 #define SMB_FLG_NOTIFY   0x40  //OBSOLETE : notify client only on open
00096 #define SMB_FLG_OPLOCKS  0x20  //OBSOLETE : req/grant oplocks
00097 #define SMB_FLG_CANON    0x10  //pathnames canonicalized (always set)
00098 #define SMB_FLG_CASELESS 0x08  //pathnames are not case sensitive (do not use)
00099 #define SMB_FLG_RESERVED 0x04  //not used
00100 #define SMB_FLG_RBP      0x02  //OBSOLETE : receive buffer posted
00101 #define SMB_FLG_LOCKREAD 0x01  //OBSOLETE : Lock/Read & Write/Unlock supported?
00102 
00103 #define SMB_FLG2_UNICODE  0x8000  //strings are unicode (not supported)
00104 #define SMB_FLG2_NTCODES  0x4000  //error codes are NT codes (always set)
00105 #define SMB_FLG2_EXECREAD 0x2000  //execute permission implies read permission
00106 #define SMB_FLG2_DFS      0x1000  //to server : resolve pathnames with DFS
00107 #define SMB_FLG2_EXTSEC   0x0800  //extended security negotiation
00108 #define SMB_FLG2_LFNREQ   0x0040  //filename in message is LFN
00109 #define SMB_FLG2_SECSIGN  0x0004  //Message Auth Code (to prevent hacks)
00110 #define SMB_FLG2_EXTATTR  0x0002  //to server : Extended Attr support (OS/2)
00111 #define SMB_FLG2_LFNSUP   0x0001  //to server : LFN supported
00112 
00113 #define SMB_CMD_MKDIR              0x00
00114 #define SMB_CMD_RMDIR              0x01
00115 #define SMB_CMD_OPEN               0x02
00116 #define SMB_CMD_CREATE_OPEN        0x03
00117 #define SMB_CMD_CLOSE              0x04
00118 #define SMB_CMD_FLUSH              0x05
00119 #define SMB_CMD_DELETE             0x06
00120 #define SMB_CMD_RENAME             0x07
00121 #define SMB_CMD_GETATTR            0x08
00122 #define SMB_CMD_SETATTR            0x09
00123 #define SMB_CMD_READ               0x0a
00124 #define SMB_CMD_WRITE              0x0b
00125 #define SMB_CMD_LOCK               0x0c
00126 #define SMB_CMD_UNLOCK             0x0d
00127 #define SMB_CMD_CREATE_TEMP        0x0e
00128 #define SMB_CMD_CREATE_ONLY        0x0f
00129 #define SMB_CMD_CHECK_PATH         0x10
00130 #define SMB_CMD_EXIT_PROCESS       0x11
00131 #define SMB_CMD_SEEK               0x12
00132 
00133 #define SMB_CMD_SET_INFO           0x22
00134 #define SMB_CMD_GET_INFO           0x23
00135 #define SMB_CMD_TRANS              0x25
00136 #define SMB_CMD_OPEN_X             0x2d
00137 
00138 #define SMB_CMD_TRANS2             0x32
00139 
00140 #define SMB_CMD_TREE_CONNECT       0x70
00141 #define SMB_CMD_TREE_DISCONNECT    0x71
00142 #define SMB_CMD_NEGOTIATE_PROTOCOL 0x72
00143 #define SMB_CMD_NEGOTIATE_LOGON_X  0x73
00144 #define SMB_CMD_TREE_CONNECT_X     0x75
00145 
00146 
00147 #define SMB_CMD_GETATTR_DISK       0x80
00148 #define SMB_CMD_FIND               0x81
00149 
00150 #define SMB_CMD_PRINT_OPEN         0xc0  //open spool file
00151 #define SMB_CMD_PRINT_WRITE        0xc1
00152 #define SMB_CMD_PRINT_CLOSE        0xc2
00153 #define SMB_CMD_PRINT_GETQUEUE     0xc3
00154 
00155 #define SMB_CMD_SEND_SINGLE        0xd0
00156 #define SMB_CMD_SEND_BROADCAST     0xd1
00157 #define SMB_CMD_FORWARD_USERNAME   0xd2
00158 #define SMB_CMD_CANCEL_FORWARD     0xd3
00159 #define SMB_CMD_GETMACHINENAME     0xd4
00160 #define SMB_CMD_START_MULTI        0xd5
00161 #define SMB_CMD_END_MULTI          0xd6
00162 #define SMB_CMD_TEXT_MULTI         0xd7  //data of multi block message
00163 
00164 #define SMB_CMD_DF_API             0xfe  //advanced DF API
00165 #define SMB_CMD_DISCONNECT         0xff  //connection closed (issued by server, not client)
00166 
00167 #define SMB_TRANS_OPEN              0x00
00168 #define SMB_TRANS_FINDFIRST         0x01
00169 #define SMB_TRANS_FINDNEXT          0x02
00170 #define SMB_TRANS_GET_FSINFO        0x03
00171 #define SMB_TRANS_SET_FSINFO        0x04
00172 #define SMB_TRANS_GET_PATHINFO      0x05
00173 #define SMB_TRANS_SET_PATHINFO      0x06
00174 #define SMB_TRANS_GET_FILEINFO      0x07
00175 #define SMB_TRANS_SET_FILEINFO      0x08
00176 #define SMB_TRANS_FIND_NOTIFY_FIRST 0x0b
00177 #define SMB_TRANS_FIND_NOTIFY_NEXT  0x0c
00178 #define SMB_TRANS_MKDIR             0x0d
00179 
00180 #define SMB_LVL_INFO_STANDARD            0x001
00181 #define SMB_LVL_EA_SIZE                  0x002
00182 #define SMB_LVL_EA_LIST                  0x003
00183 #define SMB_LVL_FILE_DIRECTORY_INFO      0x101
00184 #define SMB_LVL_FILE_FULL_DIRECTORY_INFO 0x102
00185 #define SMB_LVL_FILE_NAMES_INFO          0x103
00186 #define SMB_LVL_FILE_BOTH_DIRECTORY_INFO 0x104
00187 #define SMB_LVL_ID_FULL_DIRECTORY_INFO   0x105
00188 #define SMB_LVL_ID_BOTH_DIRECTORY_INFO   0x106
00189 
00190 //FINDFIRST flags (params[11])
00191 #define SMB_FLG_CLOSE        0x01
00192 #define SMB_FLG_CLOSE_AT_END 0x02
00193 #define SMB_FLG_RESUME_KEYS  0x04
00194 
00195 struct smb_protocol_reply {  //17 words
00196   uint16 DialectIndex;  //from list provided by client (0=start)
00197   uint8 SecurityMode;   //see SMB_FLG_SEC_...
00198   uint16 MaxMIDs;
00199   uint16 MaxVCs;
00200   uint32 MaxBufferSize;
00201   uint32 MaxRawBufSize; //OBSOLETE : use zero
00202   uint32 SessionKey;    //Rarely used : client must echo back
00203   uint32 Capabilities;  //see SMB_FLG_CAPS_...
00204   uint32 TimeLow;
00205   uint32 TimeHigh;      //1/10 microseconds from Jan 1, 1601
00206   int16 TimeZone;       //Minutes from UTC
00207   uint8 KeyLength;      //0 or 8 (use 0)
00208 };
00209 
00210 #define SMB_FLG_SEC_MAC_REQUIRED 0x08
00211 #define SMB_FLG_SEC_MAC_ENABLED  0x04
00212 #define SMB_FLG_SEC_CHALLENGE    0x02  //required (else plaintext)
00213 #define SMB_FLG_SEC_USER_LEVEL   0x01  //use Share level Mode
00214 
00215 //only those worth while listed here
00216 #define SMB_FLG_CAPS_EXT_SEC     0x80000000
00217 #define SMB_FLG_CAPS_DFS         0x00001000  //server CAPS only
00218 #define SMB_FLG_CAPS_NTCODES     0x00000040
00219 #define SMB_FLG_CAPS_64BIT       0x00000008
00220 #define SMB_FLG_CAPS_UNICODE     0x00000004
00221 
00222 union smb_protocol_reply_data { //x bytes
00223   struct {
00224     uint8 GUID[16];  //use random bytes
00225 //    uint8 Blob[];  //typical size (varies?)
00226   } ext_sec;
00227   struct {
00228 //    uint8 EncryptionKey[];  //0 or 8 bytes
00229 //    uint8 DomainName[];  //null-term
00230   } non_ext_sec;
00231 };
00232 
00233 struct smb_session_setup_andx { //to server
00234   uint8 x_cmd;
00235   uint8 reserved;
00236   uint16 x_offset;
00237   uint16 MaxBufferSize;
00238   uint16 MaxMIDs;
00239   uint16 MaxVCs;
00240   uint32 SessionKey;  //from server
00241   uint16 CIPasswordLength;  //caseless
00242   uint16 CSPasswordLength;  //case
00243   uint32 reserved2;
00244   uint32 caps;
00245 };
00246 
00247 struct smb_session_setup_andx_ext_sec { //to server
00248   uint8 x_cmd;
00249   uint8 reserved;
00250   uint16 x_offset;
00251   uint16 MaxBufferSize;
00252   uint16 MaxMIDs;
00253   uint16 MaxVCs;
00254   uint32 SessionKey;  //from server
00255   uint16 SecurityBlobLength;
00256   uint32 reserved2;
00257   uint32 caps;
00258 };
00259 
00260 

Generated on Mon Mar 5 09:49:14 2007 for DigiForce by  doxygen 1.4.7